Proxy Returning 502? Troubleshooting by Separating Request Headers from TLS Layers

    This article walks through a case where an AI development tool's requests all failed with 502 while direct calls to the same proxy succeeded. It shows how load testing ruled out traffic as the trigger, how temporary header logging exposed a silent tool upgrade and a new Authorization placeholder, and how a reproduction matrix was built to isolate each variable. It also flags which parts of the original root-cause explanation do not hold up and still need verification.

    Symptom: the tool gets 502 on every request, while direct calls through the proxy work fine

    A team configured a custom model in an AI development tool. The model endpoint pointed to a large-model gateway inside the corporate network, and requests were forwarded through a local proxy. Starting one day, every request issued by the tool returned 502, and the proxy log kept repeating the same exception:

    1. SSLEOFError: EOF occurred in violation of protocol

    This error means that some TLS connection was closed early by the peer, either during the handshake or during data transfer. It does not say which connection dropped first, and it does not say why. There are two TLS segments in the whole request path, and they need to be treated separately:

    • Tool to proxy: depends on local configuration; it may be plain HTTP, or it may go over TLS.
    • Proxy to gateway: this segment is initiated by the proxy’s TLS client, and this is where the SSLEOFError in the log comes from.

    Another observation is just as important. Calling the proxy directly from a Python script returned 200 for every request. Sending a message through the tool’s GUI returned 502 almost every time. Same proxy path, same gateway, completely different results. This strongly suggests the problem lies in the request content rather than in the network or the gateway itself. The core question therefore becomes: what exactly is the tool sending, and how does it differ from the manually tested request?

    Troubleshooting approach: rule out load first, then inspect request metadata

    The investigation ran in two rounds.

    The first round verified basic calls: single-turn conversations, concurrent calls, and continuously sent requests. The proxy layer showed no anomalies in any of these scenarios.

    The second round switched to workloads closer to real usage: requests carrying full tool definitions, both streaming and non-streaming response modes, and large request bodies containing long context plus tool-call history. These tests all passed as well.

    The original records did not preserve the full test parameters — for example concurrency, total request count, the tool version corresponding to each request-body size, the gateway configuration, and the method used to calculate failure rate. So this article gives no specific numbers and keeps only the conclusion: load is not the trigger.

    Once load was excluded, the only remaining differences could be in the HTTP headers or the authentication fields. To verify this, temporary diagnostic logging was added to the proxy to record the headers of every incoming request. Only the information needed for the diagnosis was captured, and the plaintext Authorization value was not logged. The log looked like this:

    1. Authorization: Bearer sk-p***(len=14, placeholder_hit=false)
    2. User-Agent: Some AI Dev Tool/0.1.1-rc.2

    These two fields revealed two changes.

    1. The tool had been upgraded silently. The version in the User-Agent was 0.1.1-rc.2, while the previous version in the operations records was 0.1.0. The user never upgraded manually; the tool updated itself in the background with no notification.
    2. The Authorization header carried a new placeholder. The value was not in the proxy’s placeholder list, so it did not match.

    Reproduction matrix: breaking the differences apart one by one

    Two fields alone are not enough to pin down the cause. The next step was to combine call method, authentication value, and tool version in a comparison, to confirm the effect of each factor. The table below shows the results already collected and the cases still to be tested:

    Call method Streaming Authorization Tool version Result
    Python script No Real key N/A 200
    Python script No sk-placeholder N/A To be tested
    Tool GUI Yes sk-placeholder 0.1.0 Not recorded
    Tool GUI Yes sk-placeholder 0.1.1-rc.2 502 almost every time
    Tool GUI No sk-placeholder 0.1.1-rc.2 To be tested

    The most critical case is the Python script carrying sk-placeholder. It directly separates an authentication-value cause from other tool behavior.

    Root cause analysis: which conclusions hold and which still need verification

    The original analysis assumed that the gateway detected an invalid key during the TLS handshake and therefore dropped the connection. This inference has an obvious problem.

    The TLS handshake only establishes the encrypted channel