Skip to content

Commit

Permalink
fix: SIGPIPE handling with FrankenPHP
Browse files Browse the repository at this point in the history
  • Loading branch information
dunglas committed Mar 24, 2024
1 parent 9af3c45 commit 067a2df
Showing 1 changed file with 15 additions and 4 deletions.
19 changes: 15 additions & 4 deletions amqp_connection_resource.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#else
#include <signal.h>
#include <stdint.h>
#include <stdio.h>
#endif

#if HAVE_LIBRABBITMQ_NEW_LAYOUT
Expand Down Expand Up @@ -689,15 +690,21 @@ static void connection_resource_destructor(amqp_connection_resource *resource, i
assert(resource != NULL);

#ifndef PHP_WIN32
void *old_handler;

/*
If we are trying to close the connection and the connection already closed, it will throw
SIGPIPE, which is fine, so ignore all SIGPIPES
*/

struct sigaction oldact;
struct sigaction act = { 0 };

act.sa_flags = SA_ONSTACK;
act.sa_sigaction = SIG_IGN;

/* Start ignoring SIGPIPE */
old_handler = signal(SIGPIPE, SIG_IGN);
if (sigaction(SIGPIPE, &act, &oldact) == -1) {
perror("sigaction");
}
#endif

if (resource->parent) {
Expand All @@ -720,7 +727,11 @@ static void connection_resource_destructor(amqp_connection_resource *resource, i

#ifndef PHP_WIN32
/* End ignoring of SIGPIPEs */
signal(SIGPIPE, old_handler);
oldact.sa_flags |= SA_ONSTACK;

if (sigaction(SIGPIPE, &oldact, NULL) == -1) {
perror("sigaction");
}
#endif

pefree(resource, persistent);
Expand Down

0 comments on commit 067a2df

Please sign in to comment.