Skip to content
Tcl Source Code View Ticket
Login

View Ticket

[zlib push decompress] doesn't work with [fileevent readabl]

Closed / Fixed3525907fffffffffffffffffffffffffffffffffCreated 15 years agoUpdated 15 years ago
Descriptionplain2012-05-11 17:27:33
Hi!

I've tried to use [zlib push decompress] on an unblocked network channel and found that it doesn't read from the channel if it isn't closed by the peer. In the attached script the server part puts two strings into a compressed channel (one immediately and the other after 5 second delay). Apparently, the client side readable fileevent fires many times during these 5 seconds but [read $chan] returns empty string every time. After the finishing [close] the client reads and reports the message (but only the second one!).

I would expect the both messages were printed.

Currently, I can use a separate [zlib stream decompress] and read the raw bytes from the channel, but I don't think that it's a perfect solution.
teopetukplain2012-05-12 00:27:35
File Added - 443234: zlibtest1.tcl
teopetukplain2012-05-12 00:29:03
File Added - 443236: zlibtest2.tcl
ferrieuxplain2012-05-13 22:31:44
I confirm both the strange disappearance of the bytes written before [-flush sync], and a worrisome level of syscall activity during all the 5 seconds of what should be a completely quiescent delay. Clearly, continued exchanges between the notifier and main thread occur, with a period of 7 ms. Looks like a "tamed busy loop", but I don't like it :/
andreas_kupriesplain2012-05-17 01:21:30
Moving the 

   chan configure $chan -flush sync

before the puts of the first message (still after the zlib transform is pushed) gets us both messages on the receiver side. I.e. no loss of bytes anymore. It still receives them only when the channel is closed.

I suspect that the "-flush sync" (is intended to) activate(s) the special zlib flush code forcing out the data buffered in the zlib transform without ending the zlib stream.

This part doesn't seem to work correctly.
andreas_kupriesplain2012-05-18 04:30:28
File Added - 443826: zlib-reworked-without-instrumentation.patch
andreas_kupriesplain2012-05-18 04:31:13
The attached patch seems to fix the issues, and passes the testsuite for me.
Please test.
andreas_kupriesplain2012-05-18 04:47:42
Committed change to branch bug-3525907, rev. 5ffc93920daf1775e96132f6fd826e735d84028b and descendants.
teopetukplain2012-05-18 12:16:31
I confirm that after the applying the attached patch the bug is gone.
dkfplain2012-05-19 20:15:11
Having looked at https://core.tcl.tk/tcl/vdiff?from=ba6087ec84&to=c003b262df77ede3
It looks reasonable. (I'll want to tinker with it after merger to reduce the apparent complexity, but I'll not cause this fix to be delayed for that.)

Before commit back, do we have a test for this yet?
ferrieuxplain2012-05-21 03:52:54
Test committed to the branch.
dkfplain2012-05-23 21:35:14
allow_comments - 1

Thanks to everyone who worked on this; fix merged to trunk
Log in (anonymous is fine) to add a comment.

Attachments: