jdev - 2020-02-09


  1. lovetox

    hm, if i lose internet connection, say disable wlan, my socket does not really care, i can still send endless data on it

  2. lovetox

    i thought that he would throw some error, but nothing

  3. lovetox

    now i read a bit about it and seems this works as intended

  4. lovetox

    so the only way to know if i lost connection is application layer pings

  5. lovetox

    can someone confirm this

  6. lovetox

    ?

  7. lovetox

    and there is some other functionality SO_KEEPALIVE, where the system tests if a socket is still connected

  8. lovetox

    but according to the internet the timeout is 2 hours on linux

  9. lovetox

    so not really useable as a client

  10. MattJ

    Yes, this is all correct

  11. MattJ

    There are platform-specific ways to reduce the timeout

  12. lovetox

    damn, brilliant design

  13. defanor

    Well, the send buffer is finite. And according to tcp(7) (assuming it's about TCP), keep-alive probes would lead to timing out in about 11 minutes on Linux by default, while retransmission attempts would last 13 to 30 minutes. And then there's TCP_USER_TIMEOUT, and I think I've observed it timing out in just a few minutes (not sure why).

  14. lovetox

    yeah i was looking for something in the range of seconds

  15. jonas’

    lovetox, anything in the range of seconds would make things fail on EDGE or GPRS type connections quickly

  16. pulkomandy

    Or even wifi if you're a bit far from the router

  17. MattJ

    And consume battery/bandwidth

  18. pulkomandy

    Or ethernet if you just unplug the cable for a few seconds to untangle it :]

  19. jonas’

    in the case of EDGE/GPRS, you can easily get into a fun loop with packets from your closed connection cluttering the bandwidth, making your new connection choke right away.

  20. lovetox

    hm, so what timeout would you suggest?

  21. lovetox

    i think its useful for the client to know if the connection broke down

  22. jonas’

    timeouts are always wrong

  23. lovetox

    problem is if the connection broke down, and client doesnt notice it, stuff stops working

  24. jonas’

    indeed

  25. jonas’

    I suggest to have two timeouts

  26. lovetox

    for sending a message i can just show some icon that indicates the message didnt yet reach the server

  27. jonas’

    one I call the `soft_timeout`, which is the maximum time you spend without receiving any data from the server

  28. jonas’

    (be it whitespace or a stanza)

  29. jonas’

    if the soft timeout elapses, you send a ping

  30. jonas’

    and you wait for at most `round_trip_time` (the second timeout) to receive something (doesn’t have to be a reply to your ping, anything will do)

  31. jonas’

    the good thing about this is that with high-delay links, you’ll still most of the time receive things and thus know that your stream is alive

  32. lovetox

    yeah i implemented this just now

  33. jonas’

    you also save on sending pings when you get stanzas from the server (= saved energy)

  34. lovetox

    but what is the max roundtrip tie

  35. lovetox

    but what is the max roundtrip time

  36. lovetox

    is 10 seconds good?

  37. jonas’

    in case of gajim, I’d probably set something like 5 minutes for the soft timeout, and auto-calibrate the round-trip time based on IQ round trips

  38. lovetox

    60 seconds?

  39. jonas’

    something between 60s and 120s is probably ok

  40. lovetox

    5 minutes is way to high, as i said stuff stops working, if user opens his profile it just shows a endless loading screen, if he wants to join a MUC, shows a loading screen, etc etc

  41. jonas’

    lovetox, you can make it more interactive on the application layet

  42. lovetox

    and at this time i want to give the user an indication, hey your connection may be broke down

  43. jonas’

    e.g. if after 15s you have no reply, you could do othre things

  44. jonas’

    such as pinging google or so

  45. lovetox

    but if i have a 5 minute soft timeout, i cant give the user any indication

  46. jonas’

    and if you can’t ping google, suggest that the internte may be down

  47. jonas’

    oh you can

  48. jonas’

    have an even softer 15s timeout on your requests (IQs, MUC joins etc.) which triggers some additional action to make the UX smooth

  49. jonas’

    "This is taking longer than expected. Is your internet working?"

  50. jonas’

    and also listen for OS events about connectivity changes

  51. lovetox

    so 15 seconds :)

  52. jonas’

    if you get a "reconnected to network X" event from the OS, discard your stream and resume using '198

  53. lovetox

    thats the answer i wanted

  54. jonas’

    but 15 seconds isn’t the time after which you should throw away the stream

  55. jonas’

    that’s just when you start talking to your user

  56. jonas’

    that’s also not the time after which you start sending pings

  57. jonas’

    because you just sent a "ping"

  58. jonas’

    (which is your request)

  59. lovetox

    yeah jonas’ i get it :)

  60. jonas’

    uh, although, what could be fun is trying to establish a new stream

  61. lovetox

    i was always talking about the time i wait for the poing

  62. jonas’

    in the background

  63. jonas’

    and if you notice that this works very quickly, but your request is slow, you send a ping to the server. if you don’t get a reply within the time it took to get the new stream past TLS, you know that your stream is borked and you should '198 resume on the new stream and discard the old one

  64. jonas’

    that’s neat actually

  65. jonas’

    establishing a new TCP connection and doing TLS is not that expensive in number of packets and as good as a test as anything else

  66. jonas’

    (it’ll also not clutter your own send buffers further, you can simply discard the new connection (along with its buffers) easily if it doesn’t work out)

  67. lovetox

    jonas’, sorry sounds way to complicated and over-engineered

  68. lovetox

    i wait X seconds, and throw the stream away, much easier

  69. lovetox

    thats what we have stream management for, for fast reconnects

  70. jonas’

    lovetox, that’ll really hurt you

  71. jonas’

    on a bad mobile link

  72. lovetox

    on bad mobile link, stuff will be bad, no suprise for the user :)

  73. lovetox

    but the whole topic is a nightmare, we have many actions on xmpp that need a response

  74. lovetox

    so many action will look to the user like, he clicks something but nothing happens

  75. Zash

    Show a spinner if it takes more than a few seconds

  76. lovetox

    for some things thats a fine approach

  77. lovetox

    for others its not so nice

  78. lovetox

    deleting a contact from your rosterfor example

  79. lovetox

    dont want to show a dialog with a spinner for that

  80. Zash

    Show it on the contact then. Like, replace the avatar or status icon or something

  81. lovetox

    you really have to design the whole application for this case

  82. lovetox

    what i think i will be doing, let the user send message when we lost connection

  83. lovetox

    but disable every other action

  84. flow

    > lovetox> damn, brilliant design when is a connection "lost"? I don't think there is a better design without loosing some other (desirable) properties

  85. Zash

    That's what you get when you emulate a circuit over a packet-switched network. All sorts of fun!

  86. jonas’

    lovetox, or just pretend that it has happened for things where you’re rather certain that you can enforce it to happen eventually

  87. jonas’

    for example, contact deletion

  88. jonas’

    queue the operation up and do it when you have connectivity and hide the element from the UI

  89. pep.

    And then users get confused when they use another client that has connectivity :/

  90. pep.

    I see the appeal in what you say but I'm not entirely sure I like it

  91. lovetox

    jonas’, sounds easy, but reality is much harder

  92. lovetox

    you can invest thousands of lines of code into this, and it still will be buggy

  93. lovetox

    or you just tell the user, hey right now you cant delete, wait until you have a proper connection to the server

  94. lovetox

    which is totally fine in my book, i dont think anyone expects to do server operations while offline

  95. moparisthebest

    lovetox: you can change the SO_KEEPALIVE interval on Linux, it's settable if you are root

  96. pep.

    yay gajim as root :P

  97. Zash

    Just run it in a container.

  98. pep.

    yay gajim as root in a container!

  99. jonas’

    a.k.a. flatpak?

  100. jonas’

    or was it snap?

  101. Zash

    why not both?

  102. pep.

    Is the process really root? Isn't bubblewrap used just to spawn the thing?

  103. jonas’

    pep., I was making fun of those

  104. jonas’

    probably not root ;)

  105. moparisthebest

    Well no gajim wouldn't change it, the machine administrator would

  106. moparisthebest

    With sysctl

  107. Zash

    Isn't there a per-process/-socket option you can poke if your socket library doesn't hide it from you?

  108. moparisthebest

    Not for keepalive iirc

  109. moparisthebest

    Don't worry TCP's replacement is all in userspace not kernel so you can do whatever

  110. Zash

    :(

  111. Zash

    But I was excited about TLS in kernel space

  112. Link Mauve

    I still want to play with that.

  113. Link Mauve

    I should have a look in rustls.

  114. lovetox

    so if i do the xmpp pings, i guess i dont need the send every X seconds a whitespace

  115. lovetox

    or isthis useful for something else

  116. Link Mauve

    The whitespace is a keepalive.

  117. lovetox

    yeah though i just learned a socket does not break down, even if i cut the internet, so keeping it alive is not really the issue here

  118. MattJ

    Heh

  119. MattJ

    Some (too many) routers like to silently terminate idle connections

  120. lovetox

    ok but sending a xmpp ping on a idle connection every 15 seconds should keep it alive

  121. MattJ

    Sure

  122. lovetox

    im asking if i need both

  123. MattJ

    15 seconds is kinda frequent :/

  124. MattJ

    You could at least use 198 <r>/<a> for pings, which are lighter

  125. Zash

    How about 14 minutes

  126. Link Mauve

    lovetox, that sounds like a battery drainer.

  127. Link Mauve

    Pidgin does that AFAIK, and it’s terrible.

  128. Link Mauve

    Don’t be like Pidgin.

  129. lovetox

    hm or i depend on a network manager, to tell me if the internet is down

  130. Link Mauve

    Aren’t you already doing that with nm?

  131. Link Mauve

    But jonas’’s approach of using XEP-0198 stream resumption looks quite elegant to me.

  132. Link Mauve

    That’s what I’d do if I were to start something from scratch again.

  133. lovetox

    what approach is that?

  134. Link Mauve

    The one from 10:24:16 CET.

  135. Zash

    Just trying a new TCP connection to the server would at least tell you something about whether it's the existing connection that's broken or all connectivity

  136. Link Mauve

    or all connectivity to the server*

  137. lovetox

    but thats what a network manager is for

  138. lovetox

    ...

  139. Zash

    It won't detect if someone trips over a cable in the building switch room

  140. Link Mauve

    Seems like it would require running one though.

  141. Zash

    or the server suddenly explodes

  142. lovetox

    i think we are mixing 2 things here

  143. lovetox

    detecting if my remote is gone

  144. lovetox

    and detecting if my internet is gone

  145. lovetox

    or is this the same thing?

  146. lovetox

    i hope not

  147. Link Mauve

    What is your end goal?

  148. lovetox

    either way, network manager tells me when there is no route to the internet, reading the manual

  149. lovetox

    so this includes tripping over my cable

  150. lovetox

    Link Mauve, detecting when i have no connection to the server

  151. Link Mauve

    lovetox, why do you need to know about the Internet then?

  152. Link Mauve

    And also, what do you want to do in such a case?

  153. Link Mauve

    What about if the kernel eventually flushes its buffers and messages you sent now got sent?

  154. lovetox

    i show the user that there is no connection and limit what he can do

  155. Link Mauve

    That sounds like bad UX when you can instead remember what the user did and then figure out whether it got done or not on stream resumption.

  156. Link Mauve

    Meh, stupid Freenode sending me tons of presences from IRC…

  157. Zash

    There was just a notice about them doing some maintenence

  158. Link Mauve

    poezio is still spending all of my CPU time handling those presences…

  159. lovetox

    so just a simple example

  160. lovetox

    its easy to just store the stanzas that are going out and on failed resumption replay them

  161. lovetox

    but if you think about that the user could close the application while not connected

  162. lovetox

    now you suddenly have to save your not acked stanza cache to harddisk, and on resume you have to judge which of them make sense to send

  163. MattJ

    Yes, it's hard

  164. lovetox

    you have to take into account how much time passed

  165. lovetox

    probably offer UI to ask the user etc etc

  166. lovetox

    a lot of magic that can fail, and end in scenarios where the user just cant understand what and why something happend or didnt happen

  167. lovetox

    compare this with a very simple "You are not connected, so you cant do that right now"

  168. lovetox

    but as it seems, i cant even determine if im connected :D

  169. pep.

    I agree with lovetox that it's a lot of magic that can go wrong, (buffering and resending when connectivity gets back) :/

  170. lovetox

    for messages only i can imagine it, if i would have proper UI where i notify the user of messages that have not been sent last time, and he can choose to resend

  171. lovetox

    for everything else i would say not worth it

  172. wurstsalat

    sending messages while being offline would also satisfy a feature request :)

  173. lovetox

    yeah not a problem, but we need UI first that shows that a message has not reached the server, and after X minutes, dont send it anymore instead user has to manually issue a command to resend them

  174. wurstsalat

    we could use that info bar at the top of each chat control to inform + offer to try again (and mark unsent messages in the chat)

  175. lovetox

    yeah that sentence is a week worth of work :D

  176. wurstsalat

    sorry, just trying to point out a possible UI^^

  177. wurstsalat

    I always wanted to use that infobar for more :)