Tcl Source Code

View Ticket
Login
Ticket UUID: ca6a9e5659e3a521b77bc239e1028446e9bb2e08
Title: Can't flush one line through a socket when using zlib compression/decompression
Type: Bug Created on: 2017-09-29 20:17:17
Submitter: anonymous Assigned to: nobody
Subsystem: 57. zlib Severity: Important
Priority: 5 Medium Last modified: 2017-09-29 20:17:17
Status: Open Closed by: nobody
Resolution: None Closed on:
Version: 8.6.6
Description:

When the server and client are run through two different processes, I cannot flush one line of data through a socket with zlib compression.

For example, when we have:
server.tcl
proc server {sock ip port} {
fconfigure $sock -buffering none -blocking 1
zlib push deflate $sock
puts $sock "qwertyuiop"
chan configure $sock -flush sync
flush $sock
puts "done!"
}

socket -server server 1501

vwait die

and client.tcl
set sock [socket "127.0.0.1" 1501]
fconfigure $sock -buffering none -blocking 1
zlib push inflate $sock
puts "reading.."
puts [gets $sock]
close $sock

If you start server.tcl and then start client.tcl, you will find that "qwertyuiop" from server.tcl never gets flushed. Client.tcl will simply wait to read in a line from the socket even though we see that server.tcl has indicated, "done!"

If you remove the compression, we do not see this issue. Here are the same server.tcl and client.tcl files with no compression.

server.tcl
proc server {sock ip port} {
fconfigure $sock -buffering none -blocking 1
puts $sock "qwertyuiop"
flush $sock
puts "done!"
}

socket -server server 1501

vwait die

and client.tcl
set sock [socket "127.0.0.1" 1501]
fconfigure $sock -buffering none -blocking 1
puts "reading.."
puts [gets $sock]
close $sock

If you start this new server.tcl and then the new start client.tcl, you will see that the client.tcl prints "qwertyuiop" correctly, indicating that it was flushed correctly. This is how I know that this issue is specific to zlib compression.

During my individual testing, I found that I could force the flush to happen correctly by increasing the number of "puts" operations in server.tcl. If I ran "puts $sock "qwertyuiop" 1000 times in server.tcl, I could read "qwertyuiop" correctly in client.tcl.

The bug here is that flush does not appear to be working correctly for one line with zlib compression on a socket.