rawhat / mist

gleam HTTP server. because it glistens on a web
Apache License 2.0
260 stars 11 forks source link

An error occurs with websocket #29

Closed akiomik closed 7 months ago

akiomik commented 8 months ago

I am writing a simple server using websocket. There is no problem with normal data transfer after making a connection, but the following error may occur in some cases when more data is transferred.

=ERROR REPORT==== 7-Nov-2023::01:35:07.483288 ===
Error in process <0.124.0> with exit value:
{function_clause,
    [{prim_inet,recv0,[#Port<0.13>,-6,-1],[]},
     {mist@internal@websocket,frame_from_message,3,
         [{file,
              "/Users/akiomi/src/github.com/akiomik/mist_playground/build/dev/erlang/mist/_gleam_artefacts/mist@internal@websocket.erl"},
          {line,161}]},
     {mist@internal@websocket,'-initialize_connection/5-fun-11-',4,
         [{file,
              "/Users/akiomi/src/github.com/akiomik/mist_playground/build/dev/erlang/mist/_gleam_artefacts/mist@internal@websocket.erl"},
          {line,254}]},
     {gleam_erlang_ffi,'-map_selector/2-fun-0-',3,
         [{file,
              "/Users/akiomi/src/github.com/akiomik/mist_playground/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam_erlang_ffi.erl"},
          {line,169}]},
     {gleam_erlang_ffi,select,2,
         [{file,
              "/Users/akiomi/src/github.com/akiomik/mist_playground/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam_erlang_ffi.erl"},
          {line,195}]},
     {gleam_erlang_ffi,select,1,
         [{file,
              "/Users/akiomi/src/github.com/akiomik/mist_playground/build/dev/erlang/gleam_erlang/_gleam_artefacts/gleam_erlang_ffi.erl"},
          {line,180}]},
     {gleam@otp@actor,loop,1,
         [{file,
              "/Users/akiomi/src/github.com/akiomik/mist_playground/build/dev/erlang/gleam_otp/_gleam_artefacts/gleam@otp@actor.erl"},
          {line,120}]}]}

Any ideas?

rawhat commented 8 months ago

Hmm, nothing is immediately jumping out at me. Do you have a small sample of your code (both server and client would be preferred), or a smaller replication example I could look into?

akiomik commented 8 months ago

Sorry for the delay. Here is the repository where the error is reproduced. https://github.com/akiomik/mist_playground

The code on the server side is simple. When a specific message is received, it is parsed as JSON and a response is generated based on the data it contains. https://github.com/akiomik/mist_playground/blob/main/src/mist_playground.gleam

The client side is a bit more complicated: we are testing in node.js using k6, a load testing tool made by grafana. This is a test scenario that uses five parallel connections to access the server for 1 minute. https://github.com/akiomik/mist_playground/blob/main/bench/benchmark.js

The above error occurs after about 30 seconds of starting the benchmark script in my environment.

rawhat commented 8 months ago

Thank you for the helpful reproduction steps! I think this should be fixed in the latest release.

Let me know if it works for you 😄

Edit: This wasn't fixed, but I think it should be now lol. Sorry about that.