Yes, a program running over SSH will depend on its output going somewhere. If the connection is slow, the output must be buffered somewhere, and buffers cannot be infinite, so the program must block if they are filled.
Note that the output might not necessarily go to a terminal: consider running something like
ssh user@somewhere "cat file.txt" > file.txt
This will in effect copy the file. For this to work, the output rate of cat must match that of the connection: it should be obvious that losing parts of the output from the middle would be unacceptable.
Screen will change the situation in that it acts like a terminal and will save what should be shown "on the terminal window" (plus scrollback). It doesn't need to remember everything your program outputs, only the parts that will fit the "window" and scrollback. By default, screen will wait for a slow connection (blocking the program), but it can be configured to detect a stuck connection by setting "nonblock on".
From the man page:
nonblock [on|off|numsecs]
Tell screen how to deal with user interfaces (displays) that cease
to accept output. This can happen if a user presses ^S or a TCP/modem
connection gets cut but no hangup is received. If nonblock is off
(this is the default) screen waits until the display restarts to
accept the output. If nonblock is on, screen waits until the
timeout is reached (on is treated as 1s). If the display still
doesn't receive characters, screen will consider it "blocked" and
stop sending characters to it. If at some time it restarts to accept
characters, screen will unblock the display and redisplay the updated
window contents.
A disconnection is different than a slow connection. Plain SSH cannot recover from it automatically, so your program will receive a SIGHUP. On the other hand, screen will detect a disconnection, detach and fall back to local buffering until the screen is reattached. This will not block the running program.
(Setting nonblock 1
in your .screenrc
is important if you run something like irssi that will continously produce output but still must talk to the network at the same time. Blocking would lead to getting disconnected from IRC, which is extremely annoying...)