Getting this web socket error randomly
tansandoteth
PROOP

10 months ago

I noticed my websocket connection randomly closing so I added the code below to see if its throwing an error. Here's what I found, but I am unsure if its related to Railway or not.

 const wsTransport = new WebSocketTransport(); // Accepts optional parameters
  const wsClient = new SubscriptionClient({ transport: wsTransport });

  wsClient.transport.socket.addEventListener("open", () => {
    console.log("WebSocket connection established.");
  });

  wsClient.transport.socket.addEventListener("close", () => {
    console.log("WebSocket connection closed.");
  });

  wsClient.transport.socket.addEventListener("error", (error) => {
    console.error("WebSocket error:", error);
  });

NetworkError: failed to connect to WebSocket: Didn't receive h2 alpn, aborting connection

11 Replies

tansandoteth
PROOP

10 months ago

c6b347a2-4303-459f-8d48-60e445d0b480


10 months ago

Hey, afaik Railway implements timeouts on connections made via Public Networking, make sure to implement a reconnection logic to prevent that.


tansandoteth
PROOP

10 months ago

I did end up implementing reconnection logic, but are you saying that error is a result of timing out?


10 months ago

pretty sure it is, I was also getting the same problem and from my tests Railway would drop the connection every 4-8 hours but also depends if they're doing some kind of hardware upgrade


tansandoteth
PROOP

10 months ago

okay cool! thank you!


tansandoteth
PROOP

9 months ago

Hmm… I added reconnection logic and it kept dying getting blocked by this same network error. I'm thinking I might just have to let the server error and have it restart


9 months ago

what is the time span from connection established to dying?


tansandoteth
PROOP

8 months ago

Okay, i just got it again, so it was a lot longer of a time span.

  1. This happens, but i am unsure why it happens still.

  2. My server gets into a real weird state when this happens. Right now, the server says "Crashed" whcih was like 6 min ago, but the server is also still running becuase I see new logs coming in.


tansandoteth
PROOP

8 months ago

Timestamps

1396071931270271000
1396071931647754500


tansandoteth
PROOP

8 months ago

I think 1. might be related to the socket provider's infra, but 2. is definitely strange


8 months ago

I think #2 is related to us restarting the container but not marking it as running again. If you can provide a reproducible example, that would be most helpful.


Loading...