diff --git a/lock.c b/lock.c index 3c55a68c..8c1e3f17 100644 --- a/lock.c +++ b/lock.c @@ -118,6 +118,27 @@ pid_t uwsgi_rwlock_fast_check(struct uwsgi_lock_item *uli) { #endif } + +void uwsgi_lock_fast(struct uwsgi_lock_item *uli) { + +#ifdef EOWNERDEAD + if (pthread_mutex_lock((pthread_mutex_t *) uli->lock_ptr) == EOWNERDEAD) { + uwsgi_log("[deadlock-detector] a process holding a robust mutex died. recovering...\n"); + pthread_mutex_consistent_np((pthread_mutex_t *) uli->lock_ptr); + } +#else + pthread_mutex_lock((pthread_mutex_t *) uli->lock_ptr); +#endif + uli->pid = uwsgi.mypid; +} + +void uwsgi_unlock_fast(struct uwsgi_lock_item *uli) { + + pthread_mutex_unlock((pthread_mutex_t *) uli->lock_ptr); + uli->pid = 0; + +} + void uwsgi_rlock_fast(struct uwsgi_lock_item *uli) { #ifdef OBSOLETE_LINUX_KERNEL uwsgi_lock_fast(uli); @@ -145,30 +166,10 @@ void uwsgi_rwunlock_fast(struct uwsgi_lock_item *uli) { #endif } -void uwsgi_lock_fast(struct uwsgi_lock_item *uli) { - -#ifdef EOWNERDEAD - if (pthread_mutex_lock((pthread_mutex_t *) uli->lock_ptr) == EOWNERDEAD) { - uwsgi_log("[deadlock-detector] a process holding a robust mutex died. recovering...\n"); - pthread_mutex_consistent_np((pthread_mutex_t *) uli->lock_ptr); - } -#else - pthread_mutex_lock((pthread_mutex_t *) uli->lock_ptr); -#endif - uli->pid = uwsgi.mypid; -} - -void uwsgi_unlock_fast(struct uwsgi_lock_item *uli) { - - pthread_mutex_unlock((pthread_mutex_t *) uli->lock_ptr); - uli->pid = 0; - -} - struct uwsgi_lock_item *uwsgi_rwlock_fast_init(char *id) { #ifdef OBSOLETE_LINUX_KERNEL - return uwsgi_lock_fast_init(uli); + return uwsgi_lock_fast_init(id); #else pthread_rwlockattr_t attr; diff --git a/master.c b/master.c index ae59cc33..0f8bc81c 100644 --- a/master.c +++ b/master.c @@ -140,6 +140,7 @@ void *cache_sweeper_loop(void *noarg) { } }; + return NULL; } void uwsgi_subscribe(char *subscription, uint8_t cmd) { diff --git a/proto/fastcgi.c b/proto/fastcgi.c index 8b143b62..86fc2b6e 100644 --- a/proto/fastcgi.c +++ b/proto/fastcgi.c @@ -193,22 +193,42 @@ ssize_t uwsgi_proto_fastcgi_write(struct wsgi_request * wsgi_req, char *buf, siz if (len <= 65535) { rlen = write(wsgi_req->poll.fd, &fr, 8); if (rlen <= 0) { - return rlen; + if (!uwsgi.ignore_write_errors) { + uwsgi_req_error("write()"); + } + wsgi_req->write_errors++; + return 0; } - return write(wsgi_req->poll.fd, buf, len); + rlen = write(wsgi_req->poll.fd, buf, len); + if (rlen <= 0) { + if (!uwsgi.ignore_write_errors) { + uwsgi_req_error("write()"); + } + wsgi_req->write_errors++; + return 0; + } + return rlen; } else { while(len > 0) { chunk_len = UMIN(65535, len); fr.cl = htons(chunk_len); rlen = write(wsgi_req->poll.fd, &fr, 8); - if (rlen <= 0) { - return rlen; - } + if (rlen != 8) { + if (!uwsgi.ignore_write_errors) { + uwsgi_req_error("write()"); + } + wsgi_req->write_errors++; + return 0; + } rlen = write(wsgi_req->poll.fd, ptr, chunk_len); - if (rlen <= 0) { - return rlen; - } + if (rlen != 8) { + if (!uwsgi.ignore_write_errors) { + uwsgi_req_error("write()"); + } + wsgi_req->write_errors++; + return 0; + } ptr += rlen; len -= rlen; } @@ -224,7 +244,7 @@ ssize_t uwsgi_proto_fastcgi_write_header(struct wsgi_request * wsgi_req, char *b void uwsgi_proto_fastcgi_close(struct wsgi_request *wsgi_req) { if (write(wsgi_req->poll.fd, FCGI_END_REQUEST, 24) <= 0) { - uwsgi_error("write()"); + uwsgi_req_error("write()"); } uwsgi_proto_base_close(wsgi_req); diff --git a/proto/zeromq.c b/proto/zeromq.c index 2c186291..0ff46e23 100644 --- a/proto/zeromq.c +++ b/proto/zeromq.c @@ -415,7 +415,8 @@ ssize_t uwsgi_proto_zeromq_writev_header(struct wsgi_request *wsgi_req, struct i for (i = 0; i < (int) iov_len; i++) { len = uwsgi_proto_zeromq_write(wsgi_req, iovec[i].iov_base, iovec[i].iov_len); if (len <= 0) { - return len; + wsgi_req->write_errors++; + return 0; } ret += len; } @@ -441,10 +442,13 @@ ssize_t uwsgi_proto_zeromq_write(struct wsgi_request * wsgi_req, char *buf, size zmq_msg_init_data(&reply, zmq_body, wsgi_req->proto_parser_pos + len, uwsgi_proto_zeromq_free, NULL); if (uwsgi.threads > 1) pthread_mutex_lock(&uwsgi.zmq_lock); if (zmq_send(uwsgi.zmq_pub, &reply, 0)) { - uwsgi_error("zmq_send()"); + if (!uwsgi.ignore_write_errors) { + uwsgi_error("zmq_send()"); + } + wsgi_req->write_errors++; if (uwsgi.threads > 1) pthread_mutex_unlock(&uwsgi.zmq_lock); zmq_msg_close(&reply); - return -1; + return 0; } if (uwsgi.threads > 1) pthread_mutex_unlock(&uwsgi.zmq_lock); zmq_msg_close(&reply);