Logs: a loop's thread does not write a log itself

A logger whose thread could not be started is written by its clients
themselves. A client of a loop, a fiber or a callback on the loop's
thread, would hold the loop while a database or a server takes its
line, so on a loop's thread the line is dropped instead, counted as the
log's lines dropped are.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Vladimir Dubrovin 2026-10-27 16:28:38 +03:00
parent 270b02293e
commit a5806b70ae
4 changed files with 12 additions and 0 deletions

View File

@ -338,6 +338,8 @@ int
are told to its loop. errno is left as it was. */ are told to its loop. errno is left as it was. */
void (*fiberblockfunc)(SOCKET s, short events) = NULL; void (*fiberblockfunc)(SOCKET s, short events) = NULL;
void (*fiberclosefunc)(SOCKET s) = NULL; void (*fiberclosefunc)(SOCKET s) = NULL;
/* set as well: whether this thread is a loop's, which is not to wait */
int (*onloopfunc)(void) = NULL;
#define BLOCKED(s, ev) do { if(fiberblockfunc && (errno == EAGAIN || errno == EWOULDBLOCK)) \ #define BLOCKED(s, ev) do { if(fiberblockfunc && (errno == EAGAIN || errno == EWOULDBLOCK)) \
fiberblockfunc((s), (ev)); } while(0) fiberblockfunc((s), (ev)); } while(0)

View File

@ -1049,6 +1049,14 @@ static void logdirect(struct logger *lg, struct clientparam *param, const unsign
unsigned msec, n = 0, lost = 0; unsigned msec, n = 0, lost = 0;
int res = 0, reopened = 0; int res = 0, reopened = 0;
/* a loop's thread does not wait for a log whose thread could not be
started, a database's or a server's: the line is dropped, counted */
if(onloopfunc && onloopfunc()){
_3proxy_mutex_lock(&lg->mutex);
lg->faildropped++;
_3proxy_mutex_unlock(&lg->mutex);
return;
}
lognow(&sec, &msec); lognow(&sec, &msec);
_3proxy_mutex_lock(&lg->mutex); _3proxy_mutex_lock(&lg->mutex);
if(lg->failed && sec - lg->failtime >= LOGRETRY){ if(lg->failed && sec - lg->failtime >= LOGRETRY){

View File

@ -1177,6 +1177,7 @@ static int loopsstart(void){
sockmapcbfunc = fibermap; sockmapcbfunc = fibermap;
#endif #endif
fiberpollfunc = fiberpoll; fiberpollfunc = fiberpoll;
onloopfunc = onlooper;
} }
_3proxy_mutex_unlock(&loops_mutex); _3proxy_mutex_unlock(&loops_mutex);
return !i; return !i;

View File

@ -340,6 +340,7 @@ int sockpoll(struct sockfuncs *sf, void *state, struct pollfd *fds, unsigned nfd
extern int (*fiberpollfunc)(struct pollfd *fds, unsigned nfds, int timeout); extern int (*fiberpollfunc)(struct pollfd *fds, unsigned nfds, int timeout);
extern void (*fiberblockfunc)(SOCKET s, short events); extern void (*fiberblockfunc)(SOCKET s, short events);
extern void (*fiberclosefunc)(SOCKET s); extern void (*fiberclosefunc)(SOCKET s);
extern int (*onloopfunc)(void);
int sockreadable(SOCKET s); int sockreadable(SOCKET s);
#ifndef _WIN32 #ifndef _WIN32
int fdclose(int fd); int fdclose(int fd);