olliNiinivaara / GuildenStern

Modular multithreading HTTP/1.1 + WebSocket server framework
MIT License
80 stars 7 forks source link

Occasional empty response with Keep-Alive connections #2

Closed aboisvert closed 3 years ago

aboisvert commented 3 years ago

GuildenStern seems to produce empty responses under multithreading.

I've created a small self-contained project to reproduce this at https://github.com/aboisvert/guildenbug

How to reproduce

1) Build the project with nimble build 2) Run the executable ./guildenbug 3) Go to http://localhost:8080 with your browser.

You should see the following appears:

Guildenbug
* foo1
* foo2
* foo3

This illustrates that foo1.js, foo2.js and foo3.js were all loaded correctly.

4) Keep refreshing and sometimes you should see fewer line items, indicating that one (or more) of the 3 javascript files was (were) not loaded correctly.

In Chrome, the error shows up as (failed) net::ERR_EMPTY_RESPONSE in the Developer Tools network tab. Alternatively, the console will also report the error as GET http://localhost:8080/foo1.js net::ERR_EMPTY_RESPONSE

aboisvert commented 3 years ago

See PR https://github.com/olliNiinivaara/GuildenStern/pull/3 that fixes the issue for me.

olliNiinivaara commented 3 years ago

Thank you for the fix.

It's about time I start writing some tests for this project!

I'm planning to add an optional callback to closeSocket that will report the reason why socket was closed. This callback should make debugging easier, and it should be useful also when managing websocket sessions (cookie data etc). (It is possible that your "unregister" gets merged to "closeSocket" in the process...)

Thanks again, all comments, contributions and feature requests are highly appreciated.