[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: Copas weirdness
- From: David Given <dg@...>
- Date: Tue, 05 Apr 2011 22:40:47 +0100
On 05/04/11 21:26, Fabio Mascarenhas wrote:
[...]
> Perhaps, as I do not know if you were complaining about the copas
> thread blocking or the whole program blocking.
The whole program, in that case.
Anyway, I think I've found the cause of the second failure mode, and I
think it's a copas bug.
What's happening is that I have a server handler that looks like this:
1 local clientsocket = makeconnection()
2
3 function handler(serversocket)
4 copas.receive(clientsocket, 1)
5 end
copas.receive() at line 4 will deschedule the current coroutine and wait
for input. When clientsocket becomes readable, it will be resumed by
calling _doTick() with skt=clientsocket. The read will happen,
copas.receive() will return to handler() above, and handler() will return.
However, handler() is the main function of the coroutine, so the
coroutine will now terminate and return into the same _doTick() that had
skt=clientsocket. _doTick() now correctly detects that the coroutine has
terminated and tries to close the server socket. Unfortunately, it
assumes that the last thing it blocked on was serversocket, so it just
closes skt; which of course is the wrong socket.
Commenting out the line in _doTick() which tries to close connections
means that I leak connections like mad, but everything now works (and
I'm successfully proxying ssh over HTTP).
[...]
> This was supposed to the up-to-date documentation. :-) I have commit
> access to the repo, so have just added setErrorHandler to it. Sorry.
I've also just found receivePartial(), which is astoundingly useful and
lets me get rid of a complete evil chunk of code...
--
┌─── dg@cowlark.com ───── http://www.cowlark.com ─────
│
│ "I have a mind like a steel trap. It's rusty and full of dead mice."
│ --- Anonymous, on rasfc
Attachment:
signature.asc
Description: OpenPGP digital signature