You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Long delays or stalls when refreshing terminals with lots of static text over a slow link #832
There are sometimes excessively long refresh delays with a slow link and a terminal with lots of unchanging text. When switching between tmux windows with lots of static text on a 475x125 character console, it can take many seconds to hours to refresh the terminal. Sometimes it completely stalls with the terminal partially refreshed, and while refreshing it saturates the server-to-client connection. Neither the client nor server are taking excessive CPU. The client indicates a lost connection, but if I type a hot key on the client to switch tmux at the far end to a sparsely populated window, the whole thing recovers. It fails again as soon as tmux is switched to a window with lots of text.
An ssh connection at the same time to the same tmux window refreshes in a couple of seconds.
changed the title [-]Long delays or stalls when refreshing terminals with lots of static text[/-][+]Long delays or stalls when refreshing terminals with lots of static text over a slow link[/+]on Nov 30, 2016
These are the symptoms of a MTU problem with your network. Mosh clears the Don’t Fragment flag in its packets, so large packets are supposed to get fragmented by the network and reassembled by the recipient, but some misconfigured networks drop these packets on the floor instead.
If you aren’t already using Mosh 1.2.6 on the server, that may help as it reduced the default MTU from 1380 to 1280 (#773). If you’d like to help us figure out how to work around these broken networks, see this comment.
Anders is correct in suggesting that this is probably an MTU problem, but there is one other possibility worth mentioning: Mosh communicates via application datagrams that can theoretically reach 50MB in size. These are fragmented into separate UDP datagrams by the sender and reassembled by the receiver. If any single fragment goes missing then the entire message is lost. (UDP fragmentation may also happen underneath this layer as well.) Also, the fragment reassembly is quite simple-minded, and if fragments for two separate messages are interleaved, one of the messages will be lost.
I've not actually seen this problem, but your console windows are pretty big (larger than anything I regularly use), and I think messages for windows this big might be at some risk of never being successfully delivered on networks with high loss, or with queues too short to handle all the packets in a message. Can you characterize your network link's performance at all?
If your network link is really, really low-bandwidth, I think maybe it's also possible that Mosh's timeout constants might cause it to send data at a higher rate than the link can actually deliver. ("Low-bandwidth" would be something like ISDN-B (128kb/s) or slower.)
Andersk, Cgull -- thanks for the quick response and the great info. Mosh is 1.2.6 on both client and server, and the link is about 700kbits/s. The missing fragment problem sounds possible, although as I am writing this the same problem exists and I don't see any packet loss.
I do see it try to refresh the console, and it often gets about 10%-25% of it done before it stalls. It sometimes completes the refresh on its own after that, but it's rare. Once it stalls it usually never goes any farther.
The largest packet that gets through unfragmented using ping on this link is the usual 1472 bytes, so I would think an MTU of 1280 would be conservative enough. Can the MTU used by Mosh be set somewhere? It seems a lower MTU could actually hurt when there is packet loss, since there are more fragments in a diff and the chance of one being dropped might be higher.
I looked at the troubleshooting methods in the other thread, and I'll do packet captures next time I see it happening. Should I continue with this thread or pick this up in the other one?
BTW, I never see this problem when first attaching a mosh terminal to a running tmux session. The same stalled refresh in one terminal loads fine in a different mosh connection to the same server, but only the first time. It may be solely an issue when switching windows in the tmux session. In fact I have a workaround based on this:
Connect via mosh and attach to the running tmux session. Doesn't matter what window tmux is on, since mosh always loads it fine the first time.
Give the command to switch tmux to a troublesome window. Mosh will stall loading the window.
In another console, open a second mosh connection to the server and attach to the same tmux session. The window which is stalled on the first mosh session loads just fine on the second.
Instead of switching tmux between windows on the far end, switch between consoles on the local end.
OK. Found the problem. Turned out to be the queuing algorithm in the pfsense firewall was dropping outgoing packets. Switched to another algorithm and the problem seems to be fixed.
Thanks a lot for your help and advice, and sorry to waste your time.
Interesting. I've got pfsense handy, can you describe in a little more detail how packets were getting dropped, and the config that led to this? Was the dropping a function of queue/bandwidth limits (intentional or not), or was it an algorithm doing random early drop or other non-trivial drop behavior?
I was using the CODELQ traffic shaping algorithm in pfsense at the server end, and changing to HSFC fixed the problem. Later on I let the pfsense "wizard" configure the shaper and that's also working well.
I believe codelq monitors packet transit time through the queue (outbound in this case) and drops packets to maintain desired transit times.
I suspect when switching windows in tmux, it caused the mosh server to fill the pfsense buffer, and codelq started dropping packets. Probably the mosh client was throwing it all away since it could never get a full diff (in this case an entire console window), and the mosh server was constantly resending and thus keeping the outbound queue full.
Since it seems I have an easy means to test this, please let me know if I can help.
I was able to reproduce this with pfSense 2.3.2p1 by enabling CODELQ with 700kb/s bandwidth (no other configuration) on my pfSense router's WAN and LAN interfaces, maximizing an XTerm to 163x548, loading a compile log in Emacs under tmux, and playing with ^X-3 to get multiple panes in Emacs. Monitoring server and client throughput shows the server sending about 440KB/s and the client receiving about 170KB/s, so clearly mosh-server is offering too much traffic for this link. I then tried switching to HSFC as you mention, and shut myself out of the router and network connectivity. On reboot, HSFC seemed to work OK with Mosh, and switching back to CODELQ also seemed to work (though now, an hour later, it is failing again). So I think there are pfSense issues mixed in here.
In my test case here, mosh-server sends an update every 40ms. The packets for these updates do not all reach the client but I don't have any more info than that yet. The client sends an update every 3 seconds or so-- but these updates are not received by the server. it decides the connection is no good, starts a new connection, and sends a single update. This first update on the new connection, but only the first one, is received by mosh-server. mosh-server switches to the new connection and starts sending updates again, and this cycle repeats forever. The client->server loss would appear to be a bug or configuration issue with pfSense, I would certainly not expect this low-bandwidth traffic to be dropped.
However, mosh-server should almost certainly not be sending updates every 40ms on an idle virtual terminal to a client that it can't hear-- this is obviously related to #747, but with traffic lost in the client->server path.
Activity
[-]Long delays or stalls when refreshing terminals with lots of static text[/-][+]Long delays or stalls when refreshing terminals with lots of static text over a slow link[/+]andersk commentedon Nov 30, 2016
These are the symptoms of a MTU problem with your network. Mosh clears the Don’t Fragment flag in its packets, so large packets are supposed to get fragmented by the network and reassembled by the recipient, but some misconfigured networks drop these packets on the floor instead.
If you aren’t already using Mosh 1.2.6 on the server, that may help as it reduced the default MTU from 1380 to 1280 (#773). If you’d like to help us figure out how to work around these broken networks, see this comment.
cgull commentedon Nov 30, 2016
Anders is correct in suggesting that this is probably an MTU problem, but there is one other possibility worth mentioning: Mosh communicates via application datagrams that can theoretically reach 50MB in size. These are fragmented into separate UDP datagrams by the sender and reassembled by the receiver. If any single fragment goes missing then the entire message is lost. (UDP fragmentation may also happen underneath this layer as well.) Also, the fragment reassembly is quite simple-minded, and if fragments for two separate messages are interleaved, one of the messages will be lost.
I've not actually seen this problem, but your console windows are pretty big (larger than anything I regularly use), and I think messages for windows this big might be at some risk of never being successfully delivered on networks with high loss, or with queues too short to handle all the packets in a message. Can you characterize your network link's performance at all?
cgull commentedon Nov 30, 2016
If your network link is really, really low-bandwidth, I think maybe it's also possible that Mosh's timeout constants might cause it to send data at a higher rate than the link can actually deliver. ("Low-bandwidth" would be something like ISDN-B (128kb/s) or slower.)
karlkec commentedon Nov 30, 2016
Andersk, Cgull -- thanks for the quick response and the great info. Mosh is 1.2.6 on both client and server, and the link is about 700kbits/s. The missing fragment problem sounds possible, although as I am writing this the same problem exists and I don't see any packet loss.
I do see it try to refresh the console, and it often gets about 10%-25% of it done before it stalls. It sometimes completes the refresh on its own after that, but it's rare. Once it stalls it usually never goes any farther.
The largest packet that gets through unfragmented using ping on this link is the usual 1472 bytes, so I would think an MTU of 1280 would be conservative enough. Can the MTU used by Mosh be set somewhere? It seems a lower MTU could actually hurt when there is packet loss, since there are more fragments in a diff and the chance of one being dropped might be higher.
I looked at the troubleshooting methods in the other thread, and I'll do packet captures next time I see it happening. Should I continue with this thread or pick this up in the other one?
karlkec commentedon Nov 30, 2016
BTW, I never see this problem when first attaching a mosh terminal to a running tmux session. The same stalled refresh in one terminal loads fine in a different mosh connection to the same server, but only the first time. It may be solely an issue when switching windows in the tmux session. In fact I have a workaround based on this:
karlkec commentedon Dec 1, 2016
OK. Found the problem. Turned out to be the queuing algorithm in the pfsense firewall was dropping outgoing packets. Switched to another algorithm and the problem seems to be fixed.
Thanks a lot for your help and advice, and sorry to waste your time.
cgull commentedon Dec 2, 2016
Interesting. I've got pfsense handy, can you describe in a little more detail how packets were getting dropped, and the config that led to this? Was the dropping a function of queue/bandwidth limits (intentional or not), or was it an algorithm doing random early drop or other non-trivial drop behavior?
karlkec commentedon Dec 2, 2016
I was using the CODELQ traffic shaping algorithm in pfsense at the server end, and changing to HSFC fixed the problem. Later on I let the pfsense "wizard" configure the shaper and that's also working well.
I believe codelq monitors packet transit time through the queue (outbound in this case) and drops packets to maintain desired transit times.
Here is a paper describing CoDel, and the Wikipedia article
I suspect when switching windows in tmux, it caused the mosh server to fill the pfsense buffer, and codelq started dropping packets. Probably the mosh client was throwing it all away since it could never get a full diff (in this case an entire console window), and the mosh server was constantly resending and thus keeping the outbound queue full.
Since it seems I have an easy means to test this, please let me know if I can help.
cgull commentedon Dec 3, 2016
I was able to reproduce this with pfSense 2.3.2p1 by enabling CODELQ with 700kb/s bandwidth (no other configuration) on my pfSense router's WAN and LAN interfaces, maximizing an XTerm to 163x548, loading a compile log in Emacs under tmux, and playing with ^X-3 to get multiple panes in Emacs. Monitoring server and client throughput shows the server sending about 440KB/s and the client receiving about 170KB/s, so clearly mosh-server is offering too much traffic for this link. I then tried switching to HSFC as you mention, and shut myself out of the router and network connectivity. On reboot, HSFC seemed to work OK with Mosh, and switching back to CODELQ also seemed to work (though now, an hour later, it is failing again). So I think there are pfSense issues mixed in here.
In my test case here, mosh-server sends an update every 40ms. The packets for these updates do not all reach the client but I don't have any more info than that yet. The client sends an update every 3 seconds or so-- but these updates are not received by the server. it decides the connection is no good, starts a new connection, and sends a single update. This first update on the new connection, but only the first one, is received by mosh-server. mosh-server switches to the new connection and starts sending updates again, and this cycle repeats forever. The client->server loss would appear to be a bug or configuration issue with pfSense, I would certainly not expect this low-bandwidth traffic to be dropped.
However, mosh-server should almost certainly not be sending updates every 40ms on an idle virtual terminal to a client that it can't hear-- this is obviously related to #747, but with traffic lost in the client->server path.
Add a crude exponential backoff for resent states.