Run frontier MoE models on hardware you already own — pure C, zero deps, experts streamed from disk. Tiny engine, immense model. 🐦
C
cluster: report a disconnected peer without raising SIGPIPE
Rudy Celekli4e6b9f086aff
diff --git a/c/colibri.c b/c/colibri.cindex 0c19116b..cbd08184 100644--- a/c/colibri.c+++ b/c/colibri.c@@ -3297,9 +3297,18 @@ static int expert_load(Model *m, int layer, int eid, ESlot *s, int fatal, int de#define COLI_CLUSTER_MAGIC "COLIEX01"#define COLI_CLUSTER_VERSION 1ustatic int cluster_io(int fd, void *buf, size_t n, int write_mode){+ int send_flags=0;+#ifdef MSG_NOSIGNAL+ send_flags=MSG_NOSIGNAL;+#elif defined(SO_NOSIGPIPE)+ if(write_mode){+ int enabled=1;+ if(setsockopt(fd,SOL_SOCKET,SO_NOSIGPIPE,&enabled,sizeof(enabled))!=0) return -1;+ }+#endifchar *p=(char*)buf;while(n){- ssize_t r=write_mode?send(fd,p,n,0):recv(fd,p,n,MSG_WAITALL);+ ssize_t r=write_mode?send(fd,p,n,send_flags):recv(fd,p,n,MSG_WAITALL);if(r<=0){ if(r<0&&errno==EINTR) continue; return -1; }p+=r; n-=(size_t)r;}diff --git a/c/tests/test_cluster_protocol.c b/c/tests/test_cluster_protocol.cindex 1dc4bdf5..1e1505dc 100644--- a/c/tests/test_cluster_protocol.c+++ b/c/tests/test_cluster_protocol.c@@ -7,6 +7,30 @@#include <assert.h>#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)+#include <sys/wait.h>++static void test_disconnected_peer_is_an_io_error(void)+{+ /* Use a child with the default signal disposition: a caller must receive+ * the error, even when its launcher has not globally ignored SIGPIPE. */+ pid_t child = fork();+ assert(child >= 0);+ if (child == 0) {+ int sockets[2];+ assert(socketpair(AF_UNIX, SOCK_STREAM, 0, sockets) == 0);+ close(sockets[1]);+ signal(SIGPIPE, SIG_DFL);+ char byte = 'x';+ int result = cluster_io(sockets[0], &byte, 1, 1);+ close(sockets[0]);+ assert(signal(SIGPIPE, SIG_DFL) == SIG_DFL);+ _exit(result == -1 ? 0 : 2);+ }+ int status;+ while (waitpid(child, &status, 0) < 0) assert(errno == EINTR);+ assert(WIFEXITED(status) && WEXITSTATUS(status) == 0);+}+typedef struct { int fd; int failed; } ClusterProtocolArgs;static void *cluster_protocol_worker(void *opaque)@@ -88,6 +112,7 @@ static void test_wire_round_trip(void)int main(void){#if defined(__APPLE__) || defined(__linux__) || defined(__FreeBSD__)+ test_disconnected_peer_is_an_io_error();test_wire_round_trip();puts("cluster protocol tests: ok");#else