metaeducation / ren-c

Library for embedding a Rebol interpreter into C codebases
GNU Lesser General Public License v3.0
128 stars 27 forks source link

Client thinks sub ports are still open after a server crash #1048

Closed gchiu closed 4 years ago

gchiu commented 4 years ago

if a httpd server crashes it leaves ports open

>> read http://localhost
(i) Info: use WHY for error information
** Access Error: protocol error: "Server closed connection"
** Where: fail switch awake switch switch _ wake-up if while _ wait while sync-op else _ read console
** Near: [... _
    fail error ~~]
** Line: 1346

so the client now thinks it's still got a connection to localhost which it tries to use again

>> read http://www.rebol.com
** Access Error: port is not connected: tcp://localhost:80
** Where: read if check-response switch _ wake-up if while _ wait while sync-op else _ read console
** Near: [
    read conn ~~
    return false]
** Line: 1506

where the server code is at https://gitlab.com/Zhaoshirong/rebol-chat/-/blob/master/src/s.reb commit 57c4b415e8f652beed97b7703af5cf2cf1d9f33b

hostilefork commented 4 years ago

What was happening is that an erroring-but-unrelated request was able to make it appear that other reads were failing, when really it was raising an error for a stale previous request in the polling loop.

This seems to help the issue somewhat for the case I could reproduce:

https://github.com/metaeducation/ren-c/commit/31d0e5f4d5deea9aeea9edbd78a12a59277ca055

But as we discussed in chat, the entire question of how asynchronous failures are handled needs to get some review...though I have not wanted to be the one doing that design, myself. (!)