tonyg / racket-rfc6455

RFC 6455 WebSockets support for Racket.
41 stars 7 forks source link

spontaneous internal error: tried to reschedule a dead thread #18

Open eko234 opened 3 years ago

eko234 commented 3 years ago

Hi, I'm trying to develop a web socket service, and all seems to work well, but I constantly get these errors that say that there was an attempt to reschedule a dead thread, the context for the error is the module rfc6455/conn-api.rkt:134:14. sometimes it takes 5 minutes, other times it takes more but there doesn't seem to be any reason for it, I've tried it on windows and Linux machines, compiled with raco and interpreting the source code, it is a very weird behavior, I hope you can help me out with this.

eko234 commented 3 years ago

I also tried your echo server example and tweaked the client to listen forever and make a new connection in case the current one closes, and the same happens.

djholtby commented 3 years ago

I also have this issue when a client disconnects unexpectedly. Line 134 is the executor thread.

The will breaks the ws-conn's read thread when the ws-conn gets garbage collected, and the "attempted to reschedule a dead thread" error text comes from the break code in Racket.

I believe the entire executor part can be removed. The thread holds a reference to ws-conn, so it cannot be collected while the thread is running. That means it will always be trying to break a thread that's already done.

However, the issue is that using break-thread on a thread that's dead shouldn't cause Racket to crash hard. (It should be ignored entirely, I think?)

djholtby commented 3 years ago

The Racket team has merged a fix for the break-thread issue, but it might not make it into 8.2 [update: it made it]

Meanwhile I have submitted a pull request #20 that works around the issue. I've made the thread hold the ws-conn reference weakly so that it can be collected while still live (what appears to be the intended behaviour). Now the thread stops on its own if this reference ever becomes #f