Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SDLNet_TCP_Send and SIGPIPE #2

Closed
SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Closed

SDLNet_TCP_Send and SIGPIPE #2

SDLBugzilla opened this issue Feb 11, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@SDLBugzilla
Copy link
Collaborator

This bug report was migrated from our old Bugzilla tracker.

Reported in version: unspecified
Reported for operating system, platform: Linux, All

Comments on the original bug report:

On 2006-01-31 09:25:25 +0000, Sam Lantinga wrote:

Date: Thu, 26 May 2005 15:48:34 +0300
From: Petri Latvala adrinael@nuclearzone.org
Subject: Re: [SDL] SDLNet_TCP_Send and SIGPIPE (Linux)

On Wed, Jan 19, 2005 at 05:16:04PM +0200, Antti Mannisto wrote:

My network game has worked for ages in Windows, but now that
I made a Linux version of it, there seem to be random crashes
every now and then. Everything has been made on top of SDL so the
code is identical. It is very hard to debug the problem since
a server may crash once in a month or so, but debug information
suggests that crashes might be related to SDLNet_TCP_Send.
With Valgrind, I am able to make send/SLNet_TCP_Send signal
SIGPIPE (and thus crash) when I disconnect from a server at a
certain time. It also seems that players with worse connections
are getting this problem more often.

The normal behaviour for send() is to SIGPIPE when the other end has
reset the connection, unless you pass MSG_NOSIGNAL as flags. Does
SDL_Net not do this?

Could this be a bug in SDL_net/SDL? I am using the latest library
versions (1.2.8 for SDL) and I can read in the change log that SDL
1.2.7 should have made SIGPIPE non-fatal, but what could then
explain this? Is it just Valgrind that is not working? And what
should I do to get rid of the problem? Define my own signal handler?

If SDL_Net uses send() without MSG_NOSIGNAL, it's a bug. In SDL_Net.

Would something get broken or could the problem be fixed
if I add "signal(SIGPIPE, SIG_IGN)" to somewhere in my code?
Where should it be put? After SDL and SDL_net have been initialized?

That will make you not crash, but will instead make you unable to
detect broken connections. And will make you try to send() repeatedly
to a bad fd. Don't do this.

... or you could, if you try to receive data quite directly after
trying to send, which will detect the broken connection in a nicer
way.

Disclaimer: I know nothing about the implementation of SDL_Net, I'm
just a POSIX hacker.

--
Petri Latvala

On 2006-05-01 03:37:34 +0000, Sam Lantinga wrote:

SDL_net now sets a SIGPIPE handler, for maximum portability. The semantic has always been that if SDLNet_TCP_Send() returns less data then you requested sending, then the socket has been closed, or another error has occurred.

(discussion from http://forum.sun.com/jive/thread.jspa?threadID=84670)
if you can handle EPIPE as a result from your send()/recv(), the best thing to do is a process-wide SIG_IGN for SIGPIPE.

for portable code, some of the BSD-derivatives have a socket option SO_NOSIGPIPE which lets you disable this on a per-socket basis, which is often nicer. Linux has an option to send(2) MSG_NOSIGNAL which disables SIGPIPE on a per-send() basis (not as nice as the socket option, IMO). but the only thing to work portably is to SIG_IGN it.

@SDLBugzilla SDLBugzilla added the bug Something isn't working label Feb 11, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant