• tcltls handshake runs infinitely

    From Michael Niehren@michael@niehren.de to comp.lang.tcl on Tue Oct 14 13:50:04 2025
    From Newsgroup: comp.lang.tcl

    Hi,

    i'v running an encrypted client/server network application with tcltls over xmlrpc protocol. It's implemented with coroutines and normaly runs without
    a problem.

    Now i have 2 instances where on both sides the network connection is a bit unstable. I observed that after some vague time the communication hangs and after restarting the application it runs again for a vague time and the
    error comes back.

    So i build an test scenario under linux here and try to simulate the
    unstable connection with time changed iptables commands. My debugging now
    show, that the hanging point is the tls::handshake command. It is an ansynchrous tcp connection, so the the tls::handshake command should come
    back and return an value. But in the case of the problem, it does not come
    back and runs forever, so the application hangs.

    Would it be possible to integrate an "-timeout" option into tcltls handshake
    to overcome these problem ?

    I am running tcltls V1.7.22 on tcl V8.6.16.

    Any ideas are welcome ...

    best regards
    Michael

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Petro Kazmirchuk@vivid.tree7955@fastmail.com to comp.lang.tcl on Tue Oct 14 18:56:08 2025
    From Newsgroup: comp.lang.tcl

    On 14/10/2025 13:50, Michael Niehren wrote:
    Hi,

    i'v running an encrypted client/server network application with tcltls over xmlrpc protocol. It's implemented with coroutines and normaly runs without
    a problem.

    Now i have 2 instances where on both sides the network connection is a bit unstable. I observed that after some vague time the communication hangs and after restarting the application it runs again for a vague time and the
    error comes back.

    So i build an test scenario under linux here and try to simulate the
    unstable connection with time changed iptables commands. My debugging now show, that the hanging point is the tls::handshake command. It is an ansynchrous tcp connection, so the the tls::handshake command should come back and return an value. But in the case of the problem, it does not come back and runs forever, so the application hangs.

    Would it be possible to integrate an "-timeout" option into tcltls handshake to overcome these problem ?

    I am running tcltls V1.7.22 on tcl V8.6.16.

    Any ideas are welcome ...

    best regards
    Michael


    difficult to say without full source code, but I never managed to make
    TclTLS work with async sockets, so in my project I switch the TCP socket
    to the sync mode just to perform a TLS handshake, and then switch it to
    async again:

    chan configure $sock -blocking 1
    tls::import $sock -require 1 -command tls_callback (+other options if
    needed)
    tls::handshake $sock
    chan configure $sock -blocking 0

    tls_callback can be useful for error reporting

    Note that version 1.7 is very insecure due to this bug https://core.tcl-lang.org/tcltls/tktview/3c42b2ba11

    so if possible upgrade to v2.0.b2 where it is fixed

    Best regards,
    Petro
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Petro Kazmirchuk@vivid.tree7955@fastmail.com to comp.lang.tcl on Tue Oct 14 19:02:07 2025
    From Newsgroup: comp.lang.tcl

    On 14/10/2025 18:56, Petro Kazmirchuk wrote:
    On 14/10/2025 13:50, Michael Niehren wrote:
    Hi,

    i'v running an encrypted client/server network application with tcltls
    over
    xmlrpc protocol. It's implemented with coroutines and normaly runs
    without
    a problem.

    Now i have 2 instances where on both sides the network connection is a
    bit
    unstable. I observed that after some vague time the communication
    hangs and
    after restarting the application it runs again for a vague time and the
    error comes back.

    So i build an test scenario under linux here and try to simulate the
    unstable connection with time changed iptables commands. My debugging now
    show, that the hanging point is the tls::handshake command. It is an
    ansynchrous tcp connection, so the the tls::handshake command should come
    back and return an value. But in the case of the problem, it does not
    come
    back and runs forever, so the application hangs.

    Would it be possible to integrate an "-timeout" option into tcltls
    handshake
    to overcome these problem ?

    I am running tcltls V1.7.22 on tcl V8.6.16.

    Any ideas are welcome ...

    best regards
    -a-a Michael


    difficult to say without full source code, but I never managed to make TclTLS work with async sockets, so in my project I switch the TCP socket
    to the sync mode just to perform a TLS handshake, and then switch it to async again:

    chan configure $sock -blocking 1
    tls::import $sock -require 1 -command tls_callback (+other options if needed)
    tls::handshake $sock
    chan configure $sock -blocking 0

    tls_callback can be useful for error reporting

    Note that version 1.7 is very insecure due to this bug https://core.tcl- lang.org/tcltls/tktview/3c42b2ba11

    so if possible upgrade to v2.0.b2 where it is fixed

    Best regards,
    Petro

    in fact, looking at the newsgroup discussion from 2 days ago, the new
    version might fix your unstable connection
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Brian@brian199@comcast.net to comp.lang.tcl on Tue Oct 14 13:13:59 2025
    From Newsgroup: comp.lang.tcl

    This is a multi-part message in MIME format. --------------bL0ltzIC2KapqcQYjBvezbmc
    Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit

    On 10/14/25 12:02 PM, Petro Kazmirchuk wrote:
    On 14/10/2025 18:56, Petro Kazmirchuk wrote:
    On 14/10/2025 13:50, Michael Niehren wrote:
    Hi,

    i'v running an encrypted client/server network application with
    tcltls over
    xmlrpc protocol. It's implemented with coroutines and normaly runs
    without
    a problem.

    Now i have 2 instances where on both sides the network connection is
    a bit
    unstable. I observed that after some vague time the communication
    hangs and
    after restarting the application it runs again for a vague time and the
    error comes back.

    So i build an test scenario under linux here and try to simulate the
    unstable connection with time changed iptables commands. My
    debugging now
    show, that the hanging point is the tls::handshake command. It is an
    ansynchrous tcp connection, so the the tls::handshake command should
    come
    back and return an value. But in the case of the problem, it does
    not come
    back and runs forever, so the application hangs.

    Would it be possible to integrate an "-timeout" option into tcltls
    handshake
    to overcome these problem ?

    I am running tcltls V1.7.22 on tcl V8.6.16.

    Any ideas are welcome ...

    best regards
    -a-a Michael


    difficult to say without full source code, but I never managed to
    make TclTLS work with async sockets, so in my project I switch the
    TCP socket to the sync mode just to perform a TLS handshake, and then
    switch it to async again:

    chan configure $sock -blocking 1
    tls::import $sock -require 1 -command tls_callback (+other options if
    needed)
    tls::handshake $sock
    chan configure $sock -blocking 0

    tls_callback can be useful for error reporting

    Note that version 1.7 is very insecure due to this bug
    https://core.tcl- lang.org/tcltls/tktview/3c42b2ba11

    so if possible upgrade to v2.0.b2 where it is fixed

    Best regards,
    Petro

    in fact, looking at the newsgroup discussion from 2 days ago, the new version might fix your unstable connection

    Yes, the 2.0b2 release has many improvements in this area. Please try it
    and let us know if it resolves the issue. Remember to use 'package
    prefer latest' before 'package require tls' to ensure you use the beta release. Thanks.

    https://core.tcl-lang.org/tcltls/uv/tcltls-2.0b2.tar.gz


    --------------bL0ltzIC2KapqcQYjBvezbmc
    Content-Type: text/html; charset=UTF-8
    Content-Transfer-Encoding: 8bit

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
    <div class="moz-cite-prefix">On 10/14/25 12:02 PM, Petro Kazmirchuk
    wrote:<br>
    </div>
    <blockquote type="cite" cite="mid:10clvmf$330el$1@dont-email.me">On
    14/10/2025 18:56, Petro Kazmirchuk wrote:
    <br>
    <blockquote type="cite">On 14/10/2025 13:50, Michael Niehren
    wrote:
    <br>
    <blockquote type="cite">Hi,
    <br>
    <br>
    i'v running an encrypted client/server network application
    with tcltls over
    <br>
    xmlrpc protocol. It's implemented with coroutines and normaly
    runs without
    <br>
    a problem.
    <br>
    <br>
    Now i have 2 instances where on both sides the network
    connection is a bit
    <br>
    unstable. I observed that after some vague time the
    communication hangs and
    <br>
    after restarting the application it runs again for a vague
    time and the
    <br>
    error comes back.
    <br>
    <br>
    So i build an test scenario under linux here and try to
    simulate the
    <br>
    unstable connection with time changed iptables commands. My
    debugging now
    <br>
    show, that the hanging point is the tls::handshake command. It
    is an
    <br>
    ansynchrous tcp connection, so the the tls::handshake command
    should come
    <br>
    back and return an value. But in the case of the problem, it
    does not come
    <br>
    back and runs forever, so the application hangs.
    <br>
    <br>
    Would it be possible to integrate an "-timeout" option into
    tcltls handshake
    <br>
    to overcome these problem ?
    <br>
    <br>
    I am running tcltls V1.7.22 on tcl V8.6.16.
    <br>
    <br>
    Any ideas are welcome ...
    <br>
    <br>
    best regards
    <br>
    -a-a Michael
    <br>
    <br>
    </blockquote>
    <br>
    difficult to say without full source code, but I never managed
    to make TclTLS work with async sockets, so in my project I
    switch the TCP socket to the sync mode just to perform a TLS
    handshake, and then switch it to async again:
    <br>
    <br>
    chan configure $sock -blocking 1
    <br>
    tls::import $sock -require 1 -command tls_callback (+other
    options if needed)
    <br>
    tls::handshake $sock
    <br>
    chan configure $sock -blocking 0
    <br>
    <br>
    tls_callback can be useful for error reporting
    <br>
    <br>
    Note that version 1.7 is very insecure due to this bug
    <a class="moz-txt-link-freetext" href="https://core.tcl">https://core.tcl</a>- lang.org/tcltls/tktview/3c42b2ba11
    <br>
    <br>
    so if possible upgrade to v2.0.b2 where it is fixed
    <br>
    <br>
    Best regards,
    <br>
    Petro
    <br>
    </blockquote>
    <br>
    in fact, looking at the newsgroup discussion from 2 days ago, the
    new version might fix your unstable connection
    <br>
    </blockquote>
    <p>Yes, the 2.0b2 release has many improvements in this area. Please
    try it and let us know if it resolves the issue. Remember to use
    'package prefer latest' before 'package require tls' to ensure you
    use the beta release. Thanks.</p>
    <p><a href="https://core.tcl-lang.org/tcltls/uv/tcltls-2.0b2.tar.gz"
    class="moz-txt-link-freetext">https://core.tcl-lang.org/tcltls/uv/tcltls-2.0b2.tar.gz</a></p>
    <p><br>
    </p>
    </body>
    </html>

    --------------bL0ltzIC2KapqcQYjBvezbmc--
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Niehren@michael@niehren.de to comp.lang.tcl on Tue Oct 14 23:29:24 2025
    From Newsgroup: comp.lang.tcl

    Brian wrote:

    Yes, the 2.0b2 release has many improvements in this area. Please try it
    and let us know if it resolves the issue. Remember to use 'package
    prefer latest' before 'package require tls' to ensure you use the beta release. Thanks.

    https://core.tcl-lang.org/tcltls/uv/tcltls-2.0b2.tar.gz

    Hi,

    i've checked it with 2.0b2 and run into the same problem. But i found an
    easy way to reproduce the problem. But you have to be on a linux machine.
    Take the following tcl code:

    #!/usr/bin/tclsh
    puts "tcltls version [package require tls]"

    set ::connected 0
    set sock [socket -async 192.168.70.240 2005]
    chan event $sock writable {set ::connected 1}
    vwait ::connected
    puts "connected"

    tls::import $sock -require 0

    puts "wait 5 seconds to deny traffic with iptables"
    after 5000

    puts "start handshake"
    set erg 0
    set timeout 5
    while {$erg == 0 && $timeout != 0} {
    if [catch {set erg [tls::handshake $sock]} msg] {
    puts "error: $msg"
    after 1000
    incr timeout -1
    }
    }
    puts "erg: $erg"



    At the moment where you see the wait message you have to set the iptables
    rule in another shell: iptables -I INPUT -s 192.168.70.240 -j DROP
    Then you see the "start hanshake" and it hang's. The problem occurs also if
    i ommit the -async option.

    hope that help's
    Michael
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Brian@brian199@comcast.net to comp.lang.tcl on Tue Oct 14 19:16:18 2025
    From Newsgroup: comp.lang.tcl

    This is a multi-part message in MIME format. --------------uqU0xy5FLmIIQOAT7bFRYuW0
    Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit

    On 10/14/25 4:29 PM, Michael Niehren wrote:
    Brian wrote:

    Yes, the 2.0b2 release has many improvements in this area. Please try it
    and let us know if it resolves the issue. Remember to use 'package
    prefer latest' before 'package require tls' to ensure you use the beta
    release. Thanks.

    https://core.tcl-lang.org/tcltls/uv/tcltls-2.0b2.tar.gz
    Hi,

    i've checked it with 2.0b2 and run into the same problem. But i found an
    easy way to reproduce the problem. But you have to be on a linux machine. Take the following tcl code:

    #!/usr/bin/tclsh
    puts "tcltls version [package require tls]"

    set ::connected 0
    set sock [socket -async 192.168.70.240 2005]
    chan event $sock writable {set ::connected 1}
    vwait ::connected
    puts "connected"

    tls::import $sock -require 0

    puts "wait 5 seconds to deny traffic with iptables"
    after 5000

    puts "start handshake"
    set erg 0
    set timeout 5
    while {$erg == 0 && $timeout != 0} {
    if [catch {set erg [tls::handshake $sock]} msg] {
    puts "error: $msg"
    after 1000
    incr timeout -1
    }
    }
    puts "erg: $erg"



    At the moment where you see the wait message you have to set the iptables rule in another shell: iptables -I INPUT -s 192.168.70.240 -j DROP
    Then you see the "start hanshake" and it hang's. The problem occurs also if
    i ommit the -async option.

    hope that help's
    Michael

    I can't test it the same way since I don't know what's running at that host/port, but without a service running I don't get a response. So
    since the socket is in blocking mode, it blocks forever. I added
    'fconfigure $sock -blocking 0' after the set sock line and that gets
    things moving. In debug mode (add a " --enable-debug" to configure), I
    can see it goes into an infinite loop due to errno 11=resource
    temporarily unavailable. So not sure if that's what you see, but the
    root issue is the sever isn't responding and the socket doesn't fail
    with a fatal error since currently, errno==11 is a retry condition so it
    will loop forever attempting to connect. I could add a -retry count
    limit option, but my suggestion is to add a timer to time-out after the
    socket setup but before tls::import. If it times out (connected == -1
    below), then abort. This avoids calling tls and waiting on it.

    set ::connected 0
    set sock [socket -async 192.168.70.240 2005]
    fconfigure $sock -blocking 0
    chan event $sock writable {set ::connected 1}
    after 5000 [list set ::connected -1]
    vwait ::connected
    puts "connected: $connected"
    if {$connected == -1} exit


    --------------uqU0xy5FLmIIQOAT7bFRYuW0
    Content-Type: text/html; charset=UTF-8
    Content-Transfer-Encoding: 8bit

    <!DOCTYPE html>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    </head>
    <body>
    <div class="moz-cite-prefix">On 10/14/25 4:29 PM, Michael Niehren
    wrote:<br>
    </div>
    <blockquote type="cite"
    cite="mid:nnd$42d7fd16$663d3cfa@c1638fa86f70de03">
    <pre wrap="" class="moz-quote-pre">Brian wrote:

    </pre>
    <blockquote type="cite">
    <pre wrap="" class="moz-quote-pre">Yes, the 2.0b2 release has many improvements in this area. Please try it
    and let us know if it resolves the issue. Remember to use 'package
    prefer latest' before 'package require tls' to ensure you use the beta
    release. Thanks.

    <a class="moz-txt-link-freetext" href="https://core.tcl-lang.org/tcltls/uv/tcltls-2.0b2.tar.gz">https://core.tcl-lang.org/tcltls/uv/tcltls-2.0b2.tar.gz</a>
    </pre>
    </blockquote>
    <pre wrap="" class="moz-quote-pre">
    Hi,

    i've checked it with 2.0b2 and run into the same problem. But i found an
    easy way to reproduce the problem. But you have to be on a linux machine.
    Take the following tcl code:

    #!/usr/bin/tclsh
    puts "tcltls version [package require tls]"

    set ::connected 0
    set sock [socket -async 192.168.70.240 2005]
    chan event $sock writable {set ::connected 1}
    vwait ::connected
    puts "connected"

    tls::import $sock -require 0

    puts "wait 5 seconds to deny traffic with iptables"
    after 5000

    puts "start handshake"
    set erg 0
    set timeout 5
    while {$erg == 0 &amp;&amp; $timeout != 0} {
    if [catch {set erg [tls::handshake $sock]} msg] {
    puts "error: $msg"
    after 1000
    incr timeout -1
    }
    }
    puts "erg: $erg"



    At the moment where you see the wait message you have to set the iptables
    rule in another shell: iptables -I INPUT -s 192.168.70.240 -j DROP
    Then you see the "start hanshake" and it hang's. The problem occurs also if
    i ommit the -async option.

    hope that help's
    Michael
    </pre>
    </blockquote>
    <p>I can't test it the same way since I don't know what's running at
    that host/port, but without a service running I don't get a
    response. So since the socket is in blocking mode, it blocks
    forever. I added 'fconfigure $sock -blocking 0' after the set sock
    line and that gets things moving. In debug mode (add a "-a-a<span
    style="font-family:monospace"><span
    style="color:#000000;background-color:#ffffff;">--enable-debug</span></span>"
    to configure), I can see it goes into an infinite loop due to
    errno-a-a-a<span style="font-family:monospace"><span
    style="color:#000000;background-color:#ffffff;">11=resource
    temporarily unavailable</span></span>. So not sure if that's
    what you see, but the root issue is the sever isn't responding and
    the socket doesn't fail with a fatal error since currently,
    errno==11 is a retry condition so it will loop forever attempting
    to connect. I could add a -retry count limit option, but my
    suggestion is to add a timer to time-out after the socket setup
    but before tls::import. If it times out (connected == -1 below),
    then abort. This avoids calling tls and waiting on it.</p>
    <p><font face="DEC Terminal">set ::connected 0<br>
    set sock [socket -async 192.168.70.240 2005]<br>
    fconfigure $sock -blocking 0<br>
    chan event $sock writable {set ::connected 1}<br>
    after 5000 [list set ::connected -1]<br>
    vwait ::connected<br>
    puts "connected: $connected"<br>
    if {$connected == -1} exit</font></p>
    <p><br>
    </p>
    </body>
    </html>

    --------------uqU0xy5FLmIIQOAT7bFRYuW0--
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Niehren@michael@niehren.de to comp.lang.tcl on Wed Oct 15 07:46:41 2025
    From Newsgroup: comp.lang.tcl

    Brian wrote:

    I can't test it the same way since I don't know what's running at that host/port, but without a service running I don't get a response. So
    since the socket is in blocking mode, it blocks forever. I added
    'fconfigure $sock -blocking 0' after the set sock line and that gets
    things moving. In debug mode (add a " --enable-debug" to configure), I
    can see it goes into an infinite loop due to errno 11=resource
    temporarily unavailable. So not sure if that's what you see, but the
    root issue is the sever isn't responding and the socket doesn't fail
    with a fatal error since currently, errno==11 is a retry condition so it
    will loop forever attempting to connect. I could add a -retry count
    limit option, but my suggestion is to add a timer to time-out after the socket setup but before tls::import. If it times out (connected == -1
    below), then abort. This avoids calling tls and waiting on it.

    Hi Brian,

    thanks for your effort. It's not relevant what the service does, take a
    little tcl network server which speaks tls.

    The problem with the timer is, that i can only set him to check if the connection establish or not, which i do on my "real" client, but in the
    case of an unstable connection, that i had, the described scenario takes
    place at some time. The connection is established after the socket command
    and when the call tls::handshake take place, it goes away, so i got the hanging.
    As the tls::handshake never comes back, i can not check any timeout and do something. So i think, something like the -retry option or a -timeout
    option would be the only chance to solve that.

    Greetings
    Michael

    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Niehren@michael@niehren.de to comp.lang.tcl on Wed Oct 15 08:24:28 2025
    From Newsgroup: comp.lang.tcl

    Brian wrote:

    I can't test it the same way since I don't know what's running at that host/port, but without a service running I don't get a response. So
    since the socket is in blocking mode, it blocks forever. I added
    'fconfigure $sock -blocking 0' after the set sock line and that gets
    things moving. In debug mode (add a " --enable-debug" to configure), I
    can see it goes into an infinite loop due to errno 11=resource
    temporarily unavailable. So not sure if that's what you see, but the
    root issue is the sever isn't responding and the socket doesn't fail
    with a fatal error since currently, errno==11 is a retry condition so it
    will loop forever attempting to connect. I could add a -retry count
    limit option, but my suggestion is to add a timer to time-out after the socket setup but before tls::import. If it times out (connected == -1
    below), then abort. This avoids calling tls and waiting on it.

    Hi Brian,

    as you suggested, if i set the channel to nonblocking with
    fconfigure $sock -blocking 0
    then the tls::handshake call comes back and i can handle the timeout, so
    no need for an "-retry" option.

    until now i thought, that an async channel is always in an nonblocking
    state, but that's oviously not the case. Should i set the blocking to 1
    after the handshake completes successfully ?

    Maybe someone can explain the difference of an sync channel with blocking on
    or off and an async channel with blocking on or off ... that's not clear to
    me.

    Greetings,
    Michael


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Niehren@michael@niehren.de to comp.lang.tcl on Wed Oct 15 08:41:34 2025
    From Newsgroup: comp.lang.tcl

    Brian wrote:

    I can't test it the same way since I don't know what's running at that host/port, but without a service running I don't get a response. So
    since the socket is in blocking mode, it blocks forever. I added
    'fconfigure $sock -blocking 0' after the set sock line and that gets
    things moving. In debug mode (add a " --enable-debug" to configure), I
    can see it goes into an infinite loop due to errno 11=resource
    temporarily unavailable. So not sure if that's what you see, but the
    root issue is the sever isn't responding and the socket doesn't fail
    with a fatal error since currently, errno==11 is a retry condition so it
    will loop forever attempting to connect. I could add a -retry count
    limit option, but my suggestion is to add a timer to time-out after the socket setup but before tls::import. If it times out (connected == -1
    below), then abort. This avoids calling tls and waiting on it.

    in the Wiki at https://wiki.tcl-lang.org/page/tls there is an example for
    an async connection and there is the channel explicitly set to blocking mode before the tls::handshake call and to nonblocking after that.

    That seems to be the wrong path ...


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Rich@rich@example.invalid to comp.lang.tcl on Wed Oct 15 13:38:52 2025
    From Newsgroup: comp.lang.tcl

    Michael Niehren <michael@niehren.de> wrote:
    Maybe someone can explain the difference of an sync channel with
    blocking on or off and an async channel with blocking on or off ...
    that's not clear to me.

    I've always understood the difference to be that the "-blocking on/off" setting is the control as to whether a channel is 'sync' or 'async'.
    I.e., that a 'sync' channel is a blocking channel, and that an 'async'
    channel is a non-blocking channel.

    So a 'sync channel with blocking on' is just a 'sync channel'.

    A 'sync channel with blocking off' is (while -blocking is off) an
    'async channel'.

    And, as well, the converse for 'async with -blocking on/off'.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Michael Niehren@michael@niehren.de to comp.lang.tcl on Wed Oct 15 15:50:40 2025
    From Newsgroup: comp.lang.tcl

    Rich wrote:

    Michael Niehren <michael@niehren.de> wrote:
    Maybe someone can explain the difference of an sync channel with
    blocking on or off and an async channel with blocking on or off ...
    that's not clear to me.

    I've always understood the difference to be that the "-blocking on/off" setting is the control as to whether a channel is 'sync' or 'async'.
    I.e., that a 'sync' channel is a blocking channel, and that an 'async' channel is a non-blocking channel.

    So a 'sync channel with blocking on' is just a 'sync channel'.

    A 'sync channel with blocking off' is (while -blocking is off) an
    'async channel'.

    And, as well, the converse for 'async with -blocking on/off'.

    But that seem's not to be the reality:
    If i open a channel with -async and ask with
    fconfigure $sock -blocking
    the blocking value, it is set to 1, that's the default.

    it's ab bit obscure ...
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Wed Oct 15 16:44:13 2025
    From Newsgroup: comp.lang.tcl

    Am 15.10.2025 um 02:16 schrieb Brian:
    I can't test it the same way since I don't know what's running at that host/port, but without a service running I don't get a response. So
    since the socket is in blocking mode, it blocks forever. I added
    'fconfigure $sock -blocking 0' after the set sock line and that gets
    things moving. In debug mode (add a " --enable-debug" to configure), I
    can see it goes into an infinite loop due to errno 11=resource
    temporarily unavailable. So not sure if that's what you see, but the
    root issue is the sever isn't responding and the socket doesn't fail
    with a fatal error since currently, errno==11 is a retry condition so it will loop forever attempting to connect. I could add a -retry count
    limit option, but my suggestion is to add a timer to time-out after the socket setup but before tls::import. If it times out (connected == -1 below), then abort. This avoids calling tls and waiting on it.

    If tcltls requires -blocking 0 in the connect phase, wouldnt it be
    possible to set this by TCLTLS?

    The channel driver code is very complicated.

    Blocking means, that, for example, a read for 1 byte will block until 1
    byte is received or if an error occured.
    Async means for me, that a file event is active.

    Harald


    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Brian@brian199@comcast.net to comp.lang.tcl on Wed Oct 15 13:39:49 2025
    From Newsgroup: comp.lang.tcl

    On 10/15/25 8:50 AM, Michael Niehren wrote:
    Rich wrote:

    Michael Niehren <michael@niehren.de> wrote:
    Maybe someone can explain the difference of an sync channel with
    blocking on or off and an async channel with blocking on or off ...
    that's not clear to me.

    I've always understood the difference to be that the "-blocking on/off"
    setting is the control as to whether a channel is 'sync' or 'async'.
    I.e., that a 'sync' channel is a blocking channel, and that an 'async'
    channel is a non-blocking channel.

    So a 'sync channel with blocking on' is just a 'sync channel'.

    A 'sync channel with blocking off' is (while -blocking is off) an
    'async channel'.

    And, as well, the converse for 'async with -blocking on/off'.

    But that seem's not to be the reality:
    If i open a channel with -async and ask with
    fconfigure $sock -blocking
    the blocking value, it is set to 1, that's the default.

    it's ab bit obscure ...

    The manpage seems to say that they aren't the same at least for the
    connect. From https://www.tcl-lang.org/man/tcl9.0/TclCmd/socket.html

    -async
    This option will cause the client socket to be connected
    asynchronously. This means that the socket will be created immediately
    but may not yet be connected to the server, when the call to socket returns.

    When a gets or flush is done on the socket before the connection
    attempt succeeds or fails, if the socket is in blocking mode, the
    operation will wait until the connection is completed or fails. If the
    socket is in nonblocking mode and a gets or flush is done on the socket
    before the connection attempt succeeds or fails, the operation returns immediately and fblocked on the socket returns 1. Synchronous client
    sockets may be switched (after they have connected) to operating in asynchronous mode using:

    chan configure chan -blocking 0

    See the chan configure command for more details.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Brian@brian199@comcast.net to comp.lang.tcl on Wed Oct 15 13:48:48 2025
    From Newsgroup: comp.lang.tcl

    On 10/15/25 9:44 AM, Harald Oehlmann wrote:
    Am 15.10.2025 um 02:16 schrieb Brian:
    I can't test it the same way since I don't know what's running at that
    host/port, but without a service running I don't get a response. So
    since the socket is in blocking mode, it blocks forever. I added
    'fconfigure $sock -blocking 0' after the set sock line and that gets
    things moving. In debug mode (add a " --enable-debug" to configure), I
    can see it goes into an infinite loop due to errno 11=resource
    temporarily unavailable. So not sure if that's what you see, but the
    root issue is the sever isn't responding and the socket doesn't fail
    with a fatal error since currently, errno==11 is a retry condition so
    it will loop forever attempting to connect. I could add a -retry count
    limit option, but my suggestion is to add a timer to time-out after
    the socket setup but before tls::import. If it times out (connected ==
    -1 below), then abort. This avoids calling tls and waiting on it.

    If tcltls requires -blocking 0 in the connect phase, wouldnt it be
    possible to set this by TCLTLS?

    The channel driver code is very complicated.

    Blocking means, that, for example, a read for 1 byte will block until 1
    byte is received or if an error occured.
    Async means for me, that a file event is active.

    Harald



    TLS doesn't care which mode you use. The issue is the socket needs to be connected before you initiate TLS or it will go into an infinite loop
    trying to connect if the socket is blocking. So you need to either use
    "-async -blocking 0" then periodically check if the connection has
    completed or "-blocking 1" with a time-out.

    I'm going to see if a new retry limit option would help too.
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Ralf Fassel@ralfixx@gmx.de to comp.lang.tcl on Thu Oct 16 15:53:29 2025
    From Newsgroup: comp.lang.tcl

    * Rich <rich@example.invalid>
    | Michael Niehren <michael@niehren.de> wrote:
    | > Maybe someone can explain the difference of an sync channel with
    | > blocking on or off and an async channel with blocking on or off ...
    | > that's not clear to me.

    | I've always understood the difference to be that the "-blocking on/off"
    | setting is the control as to whether a channel is 'sync' or 'async'.
    | I.e., that a 'sync' channel is a blocking channel, and that an 'async'
    | channel is a non-blocking channel.

    | So a 'sync channel with blocking on' is just a 'sync channel'.

    | A 'sync channel with blocking off' is (while -blocking is off) an
    | 'async channel'.

    | And, as well, the converse for 'async with -blocking on/off'.

    Hmmm, maybe I'm on a complete wrong path here, but in my understanding "sync/async" and "blocking/non-blocking" refer to different 'stages' of
    the socket: "sync/async" refers to the establishment of the connection,
    whereas "blocking/non-blocking" refers to the communication once the
    socket is established.

    - socket host port (ie 'sync')
    blocks while the connection is tried (you have no way to specify
    blocking/non-blocking at this stage). When the command returns, the
    connection is either established, or the connection has failed.

    - socket -async host port (ie 'async')
    returns immediately (does not block) while the connection is tried in
    the background. Success or failure of the connection has to be
    determined by other means (writeable fileevent, querying the
    connection status by [chan configure] etc)

    Only after the connection has been established, one can set blocking/non-blocking which has the usual meaning for read/write
    requests on the socket. sync/async has no relevance once the connection
    is established.

    R'
    --- Synchronet 3.21a-Linux NewsLink 1.2
  • From Harald Oehlmann@wortkarg3@yahoo.com to comp.lang.tcl on Thu Oct 16 16:14:50 2025
    From Newsgroup: comp.lang.tcl

    Am 16.10.2025 um 15:53 schrieb Ralf Fassel:
    * Rich <rich@example.invalid>
    | Michael Niehren <michael@niehren.de> wrote:
    | > Maybe someone can explain the difference of an sync channel with
    | > blocking on or off and an async channel with blocking on or off ...
    | > that's not clear to me.

    | I've always understood the difference to be that the "-blocking on/off"
    | setting is the control as to whether a channel is 'sync' or 'async'.
    | I.e., that a 'sync' channel is a blocking channel, and that an 'async'
    | channel is a non-blocking channel.

    | So a 'sync channel with blocking on' is just a 'sync channel'.

    | A 'sync channel with blocking off' is (while -blocking is off) an
    | 'async channel'.

    | And, as well, the converse for 'async with -blocking on/off'.

    Hmmm, maybe I'm on a complete wrong path here, but in my understanding "sync/async" and "blocking/non-blocking" refer to different 'stages' of
    the socket: "sync/async" refers to the establishment of the connection, whereas "blocking/non-blocking" refers to the communication once the
    socket is established.

    - socket host port (ie 'sync')
    blocks while the connection is tried (you have no way to specify
    blocking/non-blocking at this stage). When the command returns, the
    connection is either established, or the connection has failed.

    - socket -async host port (ie 'async')
    returns immediately (does not block) while the connection is tried in
    the background. Success or failure of the connection has to be
    determined by other means (writeable fileevent, querying the
    connection status by [chan configure] etc)

    Only after the connection has been established, one can set blocking/non-blocking which has the usual meaning for read/write
    requests on the socket. sync/async has no relevance once the connection
    is established.

    R'

    Right you are !

    --- Synchronet 3.21a-Linux NewsLink 1.2