From 355af026b5cc7d77280bfffe9213b12ee33dd5e1 Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Thu, 29 Jul 2021 11:16:54 -0700 Subject: [PATCH 1/2] Wait up to a second to pickup the message after trapping the SIGURG. --- ext/rbtrace.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/ext/rbtrace.c b/ext/rbtrace.c index 09de8c5..2a1a05e 100644 --- a/ext/rbtrace.c +++ b/ext/rbtrace.c @@ -1,3 +1,5 @@ +#define _POSIX_C_SOURCE 199309L + #include #include #include @@ -1062,8 +1064,11 @@ rbtrace__receive(void *data) while (true) { int ret = -1; - for (n=0; n<10 && ret==-1; n++) + // wait up to a second for the message to arrive + for (n=0; n<10 && ret==-1; n++) { ret = msgrcv(rbtracer.mqi_id, &msg, sizeof(msg)-sizeof(long), 0, IPC_NOWAIT); + nanosleep((const struct timespec[]){{0, (100 % 1000) * 1000000}}, NULL); // 100ms + } if (ret == -1) { break; From 4d21dbe1c6b3fe98a5c24516e8d839df59bd6040 Mon Sep 17 00:00:00 2001 From: Matthew Kent Date: Thu, 29 Jul 2021 14:54:40 -0700 Subject: [PATCH 2/2] Only wait when necessary. --- ext/rbtrace.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ext/rbtrace.c b/ext/rbtrace.c index 2a1a05e..3eae216 100644 --- a/ext/rbtrace.c +++ b/ext/rbtrace.c @@ -1067,7 +1067,7 @@ rbtrace__receive(void *data) // wait up to a second for the message to arrive for (n=0; n<10 && ret==-1; n++) { ret = msgrcv(rbtracer.mqi_id, &msg, sizeof(msg)-sizeof(long), 0, IPC_NOWAIT); - nanosleep((const struct timespec[]){{0, (100 % 1000) * 1000000}}, NULL); // 100ms + if (ret == -1) nanosleep((const struct timespec[]){{0, (100 % 1000) * 1000000}}, NULL); // 100ms } if (ret == -1) {