dylan-lang / http

HTTP server and client for Dylan
https://opendylan.org/package/http
MIT License
22 stars 11 forks source link

[server] Fix race condition in join-listeners #78

Closed cgay closed 9 years ago

waywardmonkeys commented 9 years ago

I think it is worth understanding how invalid listeners are ending up in the vector ... or if this is what happens when doing a f-i-p over a mutating stretchy vector.

cgay commented 9 years ago

To be clear, the problem is that #f gets into the server-listeners vector, not an invalid listener instance. The only mutations to server-listeners are via add!(..., listener) and remove!(..., listener) so it's pretty clear to me that the #f is due to the default fill for the vector. The f-i-p computes the limit at the outset of the iteration and doesn't re-check it. I don't see what else this could be.

I don't mind coding this the same way as join-clients (using with-lock) if you prefer.

waywardmonkeys commented 9 years ago

You're iterating over server-listeners using this:

for (listener in server.server-listeners)
  ...
end for;

Instead, you should:

while (~empty?(server.server-listeners))
    ...
end;
cgay commented 9 years ago

Updated.