Intermittent Response code 400 Bad Request error message on WebSocket Upgrade

Issue #234 wontfix
Former user created an issue

Hi Peter,

Many thanks for all the work you have put into the WebSocket Sampler over the years. I for one appreciate it :-)

I'm having a problem where the Open WebSocket sampler works intermittently for me. Around 20% of times the upgrade to WebSocket works fine but the remaining 80% of the time I get Response code 400 Bad Request error.

OpenWebSocketSampler: Http upgrade error in sampler 'WebSocket Open Connection' eu.luminis.websocket.HttpUpgradeException: Got unexpected status 400

The odd thing is that this is with the same script - with no modifications made between iterations. I don't believe its a backend server issue as we have a Neoload WebSocket script working correctly in the same test environment. Its must be client related but as stated above I'm not changing the script and it its working only intermittently.

I've attached screenshots and output logs of the successful & failed results.

Any help appreciated.

Thanks

Ajaz

Comments (3)

  1. Peter Doornbosch repo owner

    Hi,

    Thanks for your positive feedback.

    In general, when one encounters a 400, i always advise to check the server logs, as the server knows why the request was rejected, so the server can tell the real cause of the problem. All other attempts to find the root cause is pure guessing.

    Now, let’s see what you are guessing 😉:

    W.r.t. your question: i wonder what makes you think the sampler is wrong? Let’s analyse the http request as logged in the provide log files (i removed the clutter):

    >> GET /signalr/connect?transport=webSockets&clientProtocol=1.5&connectionToken=RfuRHwnmU7QFg5d8hDq8xOGsqrecTEQ/yGJIjuSW+Gri7SzWRdTkjV39TemqKSznWjxILPicuX9Y/ZxNwRUxoH8r7WGLHLXWm+APvg0hQW91sLXyel1M778wzDv4RD5AKMxUervdLcc5EntPxPGTzg==&connectionData=%5B%7B%22name%22%3A%22dispatcherhub%22%7D%5D&tid=4 HTTP/1.1
    >> Host: refweb.***.uk:443
    >> Cookie: ASP.NET_SessionId=2yhx1l25b322l0axzub5t2so; .EOCAUTH=CC61F7....; BIGipServer~***-Depl-WMW=rd2...
    >> Upgrade: websocket
    >> Connection: Upgrade
    >> Sec-WebSocket-Key: jQmV5aJPWL4aM3MUx+kOfA==
    >> Sec-WebSocket-Version: 13
    >>
    << HTTP/1.1 400 Bad Request
    

    So your testplan provides:

    • a URL including a token
    • three cookies

    The plugin provides:

    • the Sec-WebSocket-Key
    • (and other headers, but these are identical to a successful request)

    Now the server is rejecting you request without telling why (there could be a reason on the status line, but there isn’t 😢 ).

    The only requirement for the Sec-WebSocket-Key (see https://datatracker.ietf.org/doc/html/rfc6455#section-4.1 is that it is a 16 byte random value that is base64 encoded. Decoding jQmV5aJPWL4aM3MUx+kOfA==: 8D 09 95 E5 A2 4F 58 BE 1A 33 73 14 C7 E9 0E 7C. 16 bytes.

    What else could be wrong? Non-printable characters in the request I guess; we can’t tell unless you capture communication with WireShark.

    What else? Probably (guessing!), either the URL or the value of a cookie is wrong.

    Hth
    Peter

  2. Log in to comment