Skip to content
Tcl Source Code Ticket Change Details
Login

Ticket Change Details

Overview

Artifact ID: de31b0b65aebba48d783ed58cf8024f9222b8bd069205639018f25389a48f29b
Ticket: ca6a9e5659e3a521b77bc239e1028446e9bb2e08
Can't flush one line through a socket when using zlib compression/decompression
User & Date: anonymous on 2017-09-29 20:17:17
Changes

  1. assignee changed to: "nobody"
  2. closer changed to: "nobody"
  3. cmimetype changed to: "text/x-fossil-wiki"
  4. comment changed to:
    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:<br>
    <b>server.tcl</b><br>
    <code>proc server {sock ip port} {<br>
    fconfigure $sock -buffering none -blocking 1<br>
    zlib push deflate $sock<br>
    puts $sock "qwertyuiop"<br>
    chan configure $sock -flush sync<br>
    flush $sock<br>
    puts "done!"<br>
    }
    
    socket -server server 1501
    
    vwait die</code>
    
    <b>and client.tcl</b><br>
    <code>set sock [socket "127.0.0.1" 1501]<br>
    fconfigure $sock -buffering none -blocking 1<br>
    zlib push inflate $sock<br>
    puts "reading.."<br>
    puts [gets $sock]<br>
    close $sock</code>
    
    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.
    
    <b>server.tcl</b><br>
    <code>proc server {sock ip port} {<br>
    fconfigure $sock -buffering none -blocking 1<br>
    puts $sock "qwertyuiop"<br>
    flush $sock<br>
    puts "done!"<br>
    }
    
    socket -server server 1501
    
    vwait die</code>
    
    <b>and client.tcl</b><br>
    <code>set sock [socket "127.0.0.1" 1501]<br>
    fconfigure $sock -buffering none -blocking 1<br>
    puts "reading.."<br>
    puts [gets $sock]<br>
    close $sock</code>
    
    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.
    
  5. foundin changed to: "8.6.6"
  6. is_private changed to: "0"
  7. login: "anonymous"
  8. priority changed to: "5 Medium"
  9. private_contact changed to: "8077d0425af928b423525be2baa2a339c588525d"
  10. resolution changed to: "None"
  11. severity changed to: "Important"
  12. status changed to: "Open"
  13. submitter changed to: "anonymous"
  14. subsystem changed to: "57. zlib"
  15. title changed to:
    Can't flush one line through a socket when using zlib compression/decompression
    
  16. type changed to: "Bug"