summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--BUGS8
-rw-r--r--src/coordinator.c8
-rw-r--r--src/master.c8
-rw-r--r--src/system.c7
4 files changed, 25 insertions, 6 deletions
diff --git a/BUGS b/BUGS
new file mode 100644
index 0000000..94eb217
--- /dev/null
+++ b/BUGS
@@ -0,0 +1,8 @@
+^CUnexpected state: state=3 source=-2 action=1 (src/core/sock.c:943)
+Abort (core dumped)
+
+while terminating a master + coordinator in one daemon
+
+Windows says the same R6010 in nn_recv received -1
+
+seems to be a nn_term race in the FSM.
diff --git a/src/coordinator.c b/src/coordinator.c
index 77ff484..57642be 100644
--- a/src/coordinator.c
+++ b/src/coordinator.c
@@ -43,7 +43,6 @@ static void *coordinator_func( void *thread_data )
char *answer = NULL;
int bytes = nn_recv( coordinator_sock, &answer, NN_MSG, 0 );
- if( bytes == ETIMEDOUT ) continue;
if( coordinator_must_terminate ) continue;
if( bytes >= 0 ) {
printf( "coordinator received: %s\n", answer );
@@ -67,7 +66,8 @@ static void *coordinator_func( void *thread_data )
bytes = nn_send( coordinator_sock, msg, msg_size, 0 );
if( bytes < 0 ) {
if( errno == ETERM ) {
- goto END;
+ coordinator_must_terminate = 1;
+ continue;
} else {
fprintf( stderr, "ERROR: nn_send returned %d: %s (%d)\n",
bytes, nn_strerror( errno ), errno );
@@ -81,6 +81,9 @@ static void *coordinator_func( void *thread_data )
if( bytes < 0 ) {
if( errno == EAGAIN || errno == EINTR ) {
continue;
+ } else if( errno == ETERM ) {
+ coordinator_must_terminate = 1;
+ continue;
} else {
fprintf( stderr, "ERROR: nn_recv returned %d: %s (%d)\n",
bytes, nn_strerror( errno ), errno );
@@ -88,7 +91,6 @@ static void *coordinator_func( void *thread_data )
}
}
- END:
(void)nn_shutdown( coordinator_sock, 0 );
puts( "coordinator disconnected" );
diff --git a/src/master.c b/src/master.c
index a73a7b1..6dc764a 100644
--- a/src/master.c
+++ b/src/master.c
@@ -41,7 +41,7 @@ NEXT_DISCOVER:
int bytes = nn_send( master_sock, msg, msg_size, 0 );
if( bytes < 0 ) {
if( errno == ETERM ) {
- goto END;
+ goto MASTER_ENDS;
} else {
fprintf( stderr, "ERROR: nn_send returned %d: %s (%d)\n",
bytes, nn_strerror( errno ), errno );
@@ -72,13 +72,17 @@ NEXT_DISCOVER:
goto NEXT_DISCOVER;
} else if( errno == EAGAIN || errno == EINTR ) {
continue;
+ } else if( errno == ETERM ) {
+ master_must_terminate = 1;
+ continue;
} else {
fprintf( stderr, "ERROR: nn_recv returned %d: %s (%d)\n",
bytes, nn_strerror( errno ), errno );
}
}
}
-END:
+
+MASTER_ENDS:
(void)nn_shutdown( master_sock, 0 );
diff --git a/src/system.c b/src/system.c
index f81ba8b..0e78976 100644
--- a/src/system.c
+++ b/src/system.c
@@ -5,6 +5,7 @@
#include <windows.h>
#else
#include <unistd.h>
+#include <sys/utsname.h>
#endif
unsigned int available_cpus( void )
@@ -14,13 +15,17 @@ unsigned int available_cpus( void )
GetSystemInfo( &info );
return info.dwNumberOfProcessors;
#else
+#ifdef _SC_NPROCESSORS_ONLN
long nprocs = sysconf( _SC_NPROCESSORS_ONLN );
if( nprocs < -1 ) {
// assuming one CPU if we can't detect the number of
// CPUs (safe fallback)
return 1;
- }
+ }
return nprocs;
+#else
+ #error No _SC_NPROCESSORS_ONLN, must port first!
+#endif
#endif
}