Skip to content
Snippets Groups Projects
Commit 221507a8 authored by Rob Swindell's avatar Rob Swindell :speech_balloon:
Browse files

Reduce the Terminal Server thread outcom timeout from 80 seconds to 800 ms

Since the Terminal Server is a single thread, let's not block for long
periods of time trying to send bytes to a client (e.g. send the badip.msg
file contents to a client with a blocked IP address), effectively DoSing the
terminal server.

This should address the problem reported via IRC:
<theviper4> │Apr  9 15:38:11 viper-bbs synchronet: term Terminal Server timeout(outcom) 0000 0000
<theviper4> │Apr  9 15:38:35 viper-bbs synchronet: term Terminal Server !ERROR 110 sending on socket 39
<theviper4> │Apr  9 15:38:35 viper-bbs synchronet: term Terminal Server !ERROR 32 sending on socket 39
<theviper4> │Apr  9 15:38:35 viper-bbs synchronet: term Terminal Server !ERROR 32 sending on socket 39
<theviper4> │Apr  9 15:38:36 viper-bbs synchronet: term 0039 Telnet !CLIENT BLOCKED in ip.can: 117.95.153.33

Also, make the outcom timeout error message more helpful (e.g. include the
sock descriptor of the client) and don't use the old rioctl() function
here any more.
parent 157be9c7
Branches
Tags
1 merge request!455Update branch with changes from master
......@@ -4124,17 +4124,18 @@ int sbbs_t::_outcom(uchar ch)
}
// This outcom version retries - copied loop from sbbs_t::outchar()
int sbbs_t::outcom(uchar ch, int max_attempts)
int sbbs_t::outcom(uchar ch)
{
int i = 0;
while(_outcom(ch) != 0) {
if(!online)
break;
i++;
if(i >= max_attempts) { /* timeout - beep flush outbuf */
lprintf(LOG_NOTICE, "timeout(outcom) %04X %04X", rioctl(TXBC), rioctl(IOFO));
if(i >= outcom_max_attempts) { /* timeout - beep flush outbuf */
lprintf(LOG_NOTICE, "%04d %s TIMEOUT after %d attempts with %d bytes in transmit buffer (flushing)"
,client_socket, __FUNCTION__, i, RingBufFull(&outbuf));
RingBufReInit(&outbuf);
_outcom(BEL);
rioctl(IOCS|PAUSE);
return TXBOF;
}
if(sys_status&SS_SYSPAGE)
......@@ -5299,6 +5300,7 @@ NO_SSH:
cleanup(1);
return;
}
sbbs->outcom_max_attempts = 10;
sbbs->output_thread_running = true;
_beginthread(output_thread, 0, sbbs);
......
......@@ -509,9 +509,9 @@ public:
xpevent_t ssh_active = nullptr;
#define OUTCOM_RETRY_DELAY 80 // milliseconds
#define OUTCOM_RETRY_ATTEMPTS 1000 // 80 seconds
int _outcom(uchar ch); // send character, without retry (on buffer flow condition)
int outcom(uchar ch, int max_attempts = OUTCOM_RETRY_ATTEMPTS); // send character, with retry
int outcom_max_attempts = 1000; // 80 seconds
int _outcom(uchar ch); // send character, without retry (on buffer full condition)
int outcom(uchar ch); // send character, with retry
int incom(unsigned int timeout=0); // receive character
int kbincom(unsigned int timeout=0); // " " or return keyboard buffer
int translate_input(int ch);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment