My Twitch Bot seems to receive error code: WSAECONNRESET after 5mins~


#1

Hey Guys,

Was wondering if anyone here is able to help. I have a TwitchBot that is written in C++ with winsock2. It used to work fine, and recently picked it back up and have noticed some strange issues with it.

At first the application was just hanging on the recv() call which is blocking, which seemed normal. However, it wasn’t responding to Twitch Chat after some time, and just hung on the recv() call indefinitely.

So, implemented a timeout using the following:
DWORD timeout = 300000; /* 5 Min Timeout */
int iResult = setsockopt(m_twitchSocket, SOL_SOCKET, SO_RCVTIMEO, (char*)&timeout, sizeof(timeout));

And then ping the server if the command times out and I’ve noticed I’ve been getting this error back sometimes:

Bytes Sent: 6
PING

SocketHandler::sendMessage: send failed with error: 10054

Which after looking up on the winsock reference it’s a WSAECONNRESET, which claims the connection was closed by the other side. Does anyone know what causes this issue and why Twitch would be closing the connection to my bot?

I’ve looked through the documentation and it doesn’t look like I’m missing or breaking any of the conventions there. There’s the message limit, but I can have the bot not send any messages and it will still hit the problem.

Thanks,


#2

Usually thats down to you not PONG-ing their PING or not sending your own PING’s periodically.

May also be a local Firewall issue or a issue with your ISP shutting down IRC type connections


#3

So, I’ve continued investigating this and noticed in a a more active channel I was not getting this issue. I am currently responding to PING’s sent from the other side, but I guess that’s not frequent enough to keep the connection alive.

I decreased my timeout time from 5 minutes to 1 minute, and that seems to have fixed the problem, as I’d have stay connected than detect a disconnect and have to reconnect.

So if there’s no issues/repercussions with pinging every minute, I’ll just continue doing that then.

Thanks for the response.

To add to this, it does seem strange that my recv() call was hanging and not picking up the connection was dropped like the send() call did. May be something to investigate, but at least I have something that works now.


closed #4

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.