2 * Copyright (C) 1996-2018 The Squid Software Foundation and contributors
4 * Squid software is distributed under GPLv2+ license and includes
5 * contributions from numerous individuals and organizations.
6 * Please see the COPYING and CONTRIBUTORS files for details.
9 /* DEBUG: section 84 Helper process maintenance */
12 #include "base/AsyncCbdataCalls.h"
13 #include "base/Packable.h"
15 #include "comm/Connection.h"
16 #include "comm/Read.h"
17 #include "comm/Write.h"
20 #include "format/Quoting.h"
22 #include "helper/Reply.h"
23 #include "helper/Request.h"
25 #include "SquidConfig.h"
27 #include "SquidMath.h"
28 #include "SquidTime.h"
32 // helper_stateful_server::data uses explicit alloc()/freeOne() */
35 #define HELPER_MAX_ARGS 64
37 /// The maximum allowed request retries.
40 /// Helpers input buffer size.
41 const size_t ReadBufSize(32*1024);
43 static IOCB helperHandleRead
;
44 static IOCB helperStatefulHandleRead
;
45 static void helperServerFree(helper_server
*srv
);
46 static void helperStatefulServerFree(helper_stateful_server
*srv
);
47 static void Enqueue(helper
* hlp
, Helper::Xaction
*);
48 static helper_server
*GetFirstAvailable(const helper
* hlp
);
49 static helper_stateful_server
*StatefulGetFirstAvailable(const statefulhelper
* hlp
);
50 static void helperDispatch(helper_server
* srv
, Helper::Xaction
* r
);
51 static void helperStatefulDispatch(helper_stateful_server
* srv
, Helper::Xaction
* r
);
52 static void helperKickQueue(helper
* hlp
);
53 static void helperStatefulKickQueue(statefulhelper
* hlp
);
54 static void helperStatefulServerDone(helper_stateful_server
* srv
);
55 static void StatefulEnqueue(statefulhelper
* hlp
, Helper::Xaction
* r
);
57 CBDATA_CLASS_INIT(helper
);
58 CBDATA_CLASS_INIT(helper_server
);
59 CBDATA_CLASS_INIT(statefulhelper
);
60 CBDATA_CLASS_INIT(helper_stateful_server
);
62 InstanceIdDefinitions(HelperServerBase
, "Hlpr");
65 HelperServerBase::initStats()
75 HelperServerBase::closePipesSafely(const char *id_name
)
78 shutdown(writePipe
->fd
, SD_BOTH
);
82 if (readPipe
->fd
== writePipe
->fd
)
90 if (WaitForSingleObject(hIpc
, 5000) != WAIT_OBJECT_0
) {
92 debugs(84, DBG_IMPORTANT
, "WARNING: " << id_name
<<
93 " #" << index
<< " (PID " << (long int)pid
<< ") didn't exit in 5 seconds");
101 HelperServerBase::closeWritePipeSafely(const char *id_name
)
104 shutdown(writePipe
->fd
, (readPipe
->fd
== writePipe
->fd
? SD_BOTH
: SD_SEND
));
107 flags
.closing
= true;
108 if (readPipe
->fd
== writePipe
->fd
)
114 if (WaitForSingleObject(hIpc
, 5000) != WAIT_OBJECT_0
) {
116 debugs(84, DBG_IMPORTANT
, "WARNING: " << id_name
<<
117 " #" << index
<< " (PID " << (long int)pid
<< ") didn't exit in 5 seconds");
125 helperOpenServers(helper
* hlp
)
131 const char *args
[HELPER_MAX_ARGS
+1]; // save space for a NULL terminator
132 char fd_note_buf
[FD_DESC_SZ
];
142 if (hlp
->cmdline
== NULL
)
145 progname
= hlp
->cmdline
->key
;
147 if ((s
= strrchr(progname
, '/')))
148 shortname
= xstrdup(s
+ 1);
150 shortname
= xstrdup(progname
);
152 /* figure out how many new child are actually needed. */
153 int need_new
= hlp
->childs
.needNew();
155 debugs(84, DBG_IMPORTANT
, "helperOpenServers: Starting " << need_new
<< "/" << hlp
->childs
.n_max
<< " '" << shortname
<< "' processes");
158 debugs(84, DBG_IMPORTANT
, "helperOpenServers: No '" << shortname
<< "' processes needed.");
161 procname
= (char *)xmalloc(strlen(shortname
) + 3);
163 snprintf(procname
, strlen(shortname
) + 3, "(%s)", shortname
);
165 args
[nargs
] = procname
;
168 for (w
= hlp
->cmdline
->next
; w
&& nargs
< HELPER_MAX_ARGS
; w
= w
->next
) {
169 args
[nargs
] = w
->key
;
176 assert(nargs
<= HELPER_MAX_ARGS
);
178 for (k
= 0; k
< need_new
; ++k
) {
181 pid
= ipcCreate(hlp
->ipc_type
,
191 debugs(84, DBG_IMPORTANT
, "WARNING: Cannot run '" << progname
<< "' process.");
195 ++ hlp
->childs
.n_running
;
196 ++ hlp
->childs
.n_active
;
197 srv
= new helper_server
;
201 srv
->addr
= hlp
->addr
;
202 srv
->readPipe
= new Comm::Connection
;
203 srv
->readPipe
->fd
= rfd
;
204 srv
->writePipe
= new Comm::Connection
;
205 srv
->writePipe
->fd
= wfd
;
206 srv
->rbuf
= (char *)memAllocBuf(ReadBufSize
, &srv
->rbuf_sz
);
207 srv
->wqueue
= new MemBuf
;
209 srv
->nextRequestId
= 0;
210 srv
->replyXaction
= NULL
;
211 srv
->ignoreToEom
= false;
212 srv
->parent
= cbdataReference(hlp
);
213 dlinkAddTail(srv
, &srv
->link
, &hlp
->servers
);
216 snprintf(fd_note_buf
, FD_DESC_SZ
, "%s #%d", shortname
, k
+ 1);
217 fd_note(rfd
, fd_note_buf
);
219 snprintf(fd_note_buf
, FD_DESC_SZ
, "reading %s #%d", shortname
, k
+ 1);
220 fd_note(rfd
, fd_note_buf
);
221 snprintf(fd_note_buf
, FD_DESC_SZ
, "writing %s #%d", shortname
, k
+ 1);
222 fd_note(wfd
, fd_note_buf
);
225 commSetNonBlocking(rfd
);
228 commSetNonBlocking(wfd
);
230 AsyncCall::Pointer closeCall
= asyncCall(5,4, "helperServerFree", cbdataDialer(helperServerFree
, srv
));
231 comm_add_close_handler(rfd
, closeCall
);
233 if (hlp
->timeout
&& hlp
->childs
.concurrency
) {
234 AsyncCall::Pointer timeoutCall
= commCbCall(84, 4, "helper_server::requestTimeout",
235 CommTimeoutCbPtrFun(helper_server::requestTimeout
, srv
));
236 commSetConnTimeout(srv
->readPipe
, hlp
->timeout
, timeoutCall
);
239 AsyncCall::Pointer call
= commCbCall(5,4, "helperHandleRead",
240 CommIoCbPtrFun(helperHandleRead
, srv
));
241 comm_read(srv
->readPipe
, srv
->rbuf
, srv
->rbuf_sz
- 1, call
);
244 hlp
->last_restart
= squid_curtime
;
245 safe_free(shortname
);
247 helperKickQueue(hlp
);
253 * helperStatefulOpenServers: create the stateful child helper processes
256 helperStatefulOpenServers(statefulhelper
* hlp
)
259 const char *args
[HELPER_MAX_ARGS
+1]; // save space for a NULL terminator
260 char fd_note_buf
[FD_DESC_SZ
];
263 if (hlp
->cmdline
== NULL
)
266 if (hlp
->childs
.concurrency
)
267 debugs(84, DBG_CRITICAL
, "ERROR: concurrency= is not yet supported for stateful helpers ('" << hlp
->cmdline
<< "')");
269 char *progname
= hlp
->cmdline
->key
;
272 if ((s
= strrchr(progname
, '/')))
273 shortname
= xstrdup(s
+ 1);
275 shortname
= xstrdup(progname
);
277 /* figure out haw mant new helpers are needed. */
278 int need_new
= hlp
->childs
.needNew();
280 debugs(84, DBG_IMPORTANT
, "helperOpenServers: Starting " << need_new
<< "/" << hlp
->childs
.n_max
<< " '" << shortname
<< "' processes");
283 debugs(84, DBG_IMPORTANT
, "helperStatefulOpenServers: No '" << shortname
<< "' processes needed.");
286 char *procname
= (char *)xmalloc(strlen(shortname
) + 3);
288 snprintf(procname
, strlen(shortname
) + 3, "(%s)", shortname
);
290 args
[nargs
] = procname
;
293 for (wordlist
*w
= hlp
->cmdline
->next
; w
&& nargs
< HELPER_MAX_ARGS
; w
= w
->next
) {
294 args
[nargs
] = w
->key
;
301 assert(nargs
<= HELPER_MAX_ARGS
);
303 for (int k
= 0; k
< need_new
; ++k
) {
308 pid_t pid
= ipcCreate(hlp
->ipc_type
,
318 debugs(84, DBG_IMPORTANT
, "WARNING: Cannot run '" << progname
<< "' process.");
322 ++ hlp
->childs
.n_running
;
323 ++ hlp
->childs
.n_active
;
324 helper_stateful_server
*srv
= new helper_stateful_server
;
327 srv
->flags
.reserved
= false;
329 srv
->addr
= hlp
->addr
;
330 srv
->readPipe
= new Comm::Connection
;
331 srv
->readPipe
->fd
= rfd
;
332 srv
->writePipe
= new Comm::Connection
;
333 srv
->writePipe
->fd
= wfd
;
334 srv
->rbuf
= (char *)memAllocBuf(ReadBufSize
, &srv
->rbuf_sz
);
336 srv
->parent
= cbdataReference(hlp
);
338 dlinkAddTail(srv
, &srv
->link
, &hlp
->servers
);
341 snprintf(fd_note_buf
, FD_DESC_SZ
, "%s #%d", shortname
, k
+ 1);
342 fd_note(rfd
, fd_note_buf
);
344 snprintf(fd_note_buf
, FD_DESC_SZ
, "reading %s #%d", shortname
, k
+ 1);
345 fd_note(rfd
, fd_note_buf
);
346 snprintf(fd_note_buf
, FD_DESC_SZ
, "writing %s #%d", shortname
, k
+ 1);
347 fd_note(wfd
, fd_note_buf
);
350 commSetNonBlocking(rfd
);
353 commSetNonBlocking(wfd
);
355 AsyncCall::Pointer closeCall
= asyncCall(5,4, "helperStatefulServerFree", cbdataDialer(helperStatefulServerFree
, srv
));
356 comm_add_close_handler(rfd
, closeCall
);
358 AsyncCall::Pointer call
= commCbCall(5,4, "helperStatefulHandleRead",
359 CommIoCbPtrFun(helperStatefulHandleRead
, srv
));
360 comm_read(srv
->readPipe
, srv
->rbuf
, srv
->rbuf_sz
- 1, call
);
363 hlp
->last_restart
= squid_curtime
;
364 safe_free(shortname
);
366 helperStatefulKickQueue(hlp
);
370 helper::submitRequest(Helper::Xaction
*r
)
374 if ((srv
= GetFirstAvailable(this)))
375 helperDispatch(srv
, r
);
382 /// handles helperSubmit() and helperStatefulSubmit() failures
384 SubmissionFailure(helper
*hlp
, HLPCB
*callback
, void *data
)
386 auto result
= Helper::Error
;
388 debugs(84, 3, "no helper");
389 result
= Helper::Unknown
;
391 // else pretend the helper has responded with ERR
393 callback(data
, Helper::Reply(result
));
397 helperSubmit(helper
* hlp
, const char *buf
, HLPCB
* callback
, void *data
)
399 if (!hlp
|| !hlp
->trySubmit(buf
, callback
, data
))
400 SubmissionFailure(hlp
, callback
, data
);
403 /// whether queuing an additional request would overload the helper
405 helper::queueFull() const {
406 return stats
.queue_size
>= static_cast<int>(childs
.queue_size
);
410 helper::overloaded() const {
411 return stats
.queue_size
> static_cast<int>(childs
.queue_size
);
414 /// synchronizes queue-dependent measurements with the current queue state
416 helper::syncQueueStats()
420 debugs(84, 5, id_name
<< " still overloaded; dropped " << droppedRequests
);
422 overloadStart
= squid_curtime
;
423 debugs(84, 3, id_name
<< " became overloaded");
427 debugs(84, 5, id_name
<< " is no longer overloaded");
428 if (droppedRequests
) {
429 debugs(84, DBG_IMPORTANT
, "helper " << id_name
<<
430 " is no longer overloaded after dropping " << droppedRequests
<<
431 " requests in " << (squid_curtime
- overloadStart
) << " seconds");
439 /// prepares the helper for request submission
440 /// returns true if and only if the submission should proceed
441 /// may kill Squid if the helper remains overloaded for too long
445 // re-sync for the configuration may have changed since the last submission
448 // Nothing special to do if the new request does not overload (i.e., the
449 // queue is not even full yet) or only _starts_ overloading this helper
450 // (i.e., the queue is currently at its limit).
454 if (squid_curtime
- overloadStart
<= 180)
455 return true; // also OK: overload has not persisted long enough to panic
457 if (childs
.onPersistentOverload
== Helper::ChildConfig::actDie
)
458 fatalf("Too many queued %s requests; see on-persistent-overload.", id_name
);
460 if (!droppedRequests
) {
461 debugs(84, DBG_IMPORTANT
, "WARNING: dropping requests to overloaded " <<
462 id_name
<< " helper configured with on-persistent-overload=err");
465 debugs(84, 3, "failed to send " << droppedRequests
<< " helper requests to " << id_name
);
470 helper::trySubmit(const char *buf
, HLPCB
* callback
, void *data
)
473 return false; // request was dropped
475 submit(buf
, callback
, data
); // will send or queue
476 return true; // request submitted or queued
479 /// dispatches or enqueues a helper requests; does not enforce queue limits
481 helper::submit(const char *buf
, HLPCB
* callback
, void *data
)
483 Helper::Xaction
*r
= new Helper::Xaction(callback
, data
, buf
);
485 debugs(84, DBG_DATA
, Raw("buf", buf
, strlen(buf
)));
488 /// lastserver = "server last used as part of a reserved request sequence"
490 helperStatefulSubmit(statefulhelper
* hlp
, const char *buf
, HLPCB
* callback
, void *data
, helper_stateful_server
* lastserver
)
492 if (!hlp
|| !hlp
->trySubmit(buf
, callback
, data
, lastserver
))
493 SubmissionFailure(hlp
, callback
, data
);
496 /// If possible, submit request. Otherwise, either kill Squid or return false.
498 statefulhelper::trySubmit(const char *buf
, HLPCB
* callback
, void *data
, helper_stateful_server
*lastserver
)
501 return false; // request was dropped
503 submit(buf
, callback
, data
, lastserver
); // will send or queue
504 return true; // request submitted or queued
507 void statefulhelper::submit(const char *buf
, HLPCB
* callback
, void *data
, helper_stateful_server
* lastserver
)
509 Helper::Xaction
*r
= new Helper::Xaction(callback
, data
, buf
);
511 if ((buf
!= NULL
) && lastserver
) {
512 debugs(84, 5, "StatefulSubmit with lastserver " << lastserver
);
513 assert(lastserver
->flags
.reserved
);
514 assert(!lastserver
->requests
.size());
516 debugs(84, 5, "StatefulSubmit dispatching");
517 helperStatefulDispatch(lastserver
, r
);
519 helper_stateful_server
*srv
;
520 if ((srv
= StatefulGetFirstAvailable(this))) {
521 helperStatefulDispatch(srv
, r
);
523 StatefulEnqueue(this, r
);
526 debugs(84, DBG_DATA
, "placeholder: '" << r
->request
.placeholder
<<
527 "', " << Raw("buf", buf
, (!buf
?0:strlen(buf
))));
535 * helperStatefulReleaseServer tells the helper that whoever was
536 * using it no longer needs its services.
539 helperStatefulReleaseServer(helper_stateful_server
* srv
)
541 debugs(84, 3, HERE
<< "srv-" << srv
->index
<< " flags.reserved = " << srv
->flags
.reserved
);
542 if (!srv
->flags
.reserved
)
545 ++ srv
->stats
.releases
;
547 srv
->flags
.reserved
= false;
549 helperStatefulServerDone(srv
);
553 helper::packStatsInto(Packable
*p
, const char *label
) const
556 p
->appendf("%s:\n", label
);
558 p
->appendf(" program: %s\n", cmdline
->key
);
559 p
->appendf(" number active: %d of %d (%d shutting down)\n", childs
.n_active
, childs
.n_max
, (childs
.n_running
- childs
.n_active
));
560 p
->appendf(" requests sent: %d\n", stats
.requests
);
561 p
->appendf(" replies received: %d\n", stats
.replies
);
562 p
->appendf(" requests timedout: %d\n", stats
.timedout
);
563 p
->appendf(" queue length: %d\n", stats
.queue_size
);
564 p
->appendf(" avg service time: %d msec\n", stats
.avg_svc_time
);
566 p
->appendf("%7s\t%7s\t%7s\t%11s\t%11s\t%11s\t%6s\t%7s\t%7s\t%7s\n",
578 for (dlink_node
*link
= servers
.head
; link
; link
= link
->next
) {
579 HelperServerBase
*srv
= static_cast<HelperServerBase
*>(link
->data
);
581 Helper::Xaction
*xaction
= srv
->requests
.empty() ? NULL
: srv
->requests
.front();
582 double tt
= 0.001 * (xaction
? tvSubMsec(xaction
->request
.dispatch_time
, current_time
) : tvSubMsec(srv
->dispatch_time
, srv
->answer_time
));
583 p
->appendf("%7u\t%7d\t%7d\t%11" PRIu64
"\t%11" PRIu64
"\t%11" PRIu64
"\t%c%c%c%c%c%c\t%7.3f\t%7d\t%s\n",
590 srv
->stats
.pending
? 'B' : ' ',
591 srv
->flags
.writing
? 'W' : ' ',
592 srv
->flags
.closing
? 'C' : ' ',
593 srv
->flags
.reserved
? 'R' : ' ',
594 srv
->flags
.shutdown
? 'S' : ' ',
595 xaction
&& xaction
->request
.placeholder
? 'P' : ' ',
598 xaction
? Format::QuoteMimeBlob(xaction
->request
.buf
) : "(none)");
601 p
->append("\nFlags key:\n"
606 " S\tSHUTDOWN PENDING\n"
607 " P\tPLACEHOLDER\n", 101);
611 helper::willOverload() const {
612 return queueFull() && !(childs
.needNew() || GetFirstAvailable(this));
616 helperShutdown(helper
* hlp
)
618 dlink_node
*link
= hlp
->servers
.head
;
622 srv
= (helper_server
*)link
->data
;
625 if (srv
->flags
.shutdown
) {
626 debugs(84, 3, "helperShutdown: " << hlp
->id_name
<< " #" << srv
->index
<< " has already SHUT DOWN.");
630 assert(hlp
->childs
.n_active
> 0);
631 -- hlp
->childs
.n_active
;
632 srv
->flags
.shutdown
= true; /* request it to shut itself down */
634 if (srv
->flags
.closing
) {
635 debugs(84, 3, "helperShutdown: " << hlp
->id_name
<< " #" << srv
->index
<< " is CLOSING.");
639 if (srv
->stats
.pending
) {
640 debugs(84, 3, "helperShutdown: " << hlp
->id_name
<< " #" << srv
->index
<< " is BUSY.");
644 debugs(84, 3, "helperShutdown: " << hlp
->id_name
<< " #" << srv
->index
<< " shutting down.");
645 /* the rest of the details is dealt with in the helperServerFree
648 srv
->closePipesSafely(hlp
->id_name
);
653 helperStatefulShutdown(statefulhelper
* hlp
)
655 dlink_node
*link
= hlp
->servers
.head
;
656 helper_stateful_server
*srv
;
659 srv
= (helper_stateful_server
*)link
->data
;
662 if (srv
->flags
.shutdown
) {
663 debugs(84, 3, "helperStatefulShutdown: " << hlp
->id_name
<< " #" << srv
->index
<< " has already SHUT DOWN.");
667 assert(hlp
->childs
.n_active
> 0);
668 -- hlp
->childs
.n_active
;
669 srv
->flags
.shutdown
= true; /* request it to shut itself down */
671 if (srv
->stats
.pending
) {
672 debugs(84, 3, "helperStatefulShutdown: " << hlp
->id_name
<< " #" << srv
->index
<< " is BUSY.");
676 if (srv
->flags
.closing
) {
677 debugs(84, 3, "helperStatefulShutdown: " << hlp
->id_name
<< " #" << srv
->index
<< " is CLOSING.");
681 if (srv
->flags
.reserved
) {
683 debugs(84, 3, "helperStatefulShutdown: " << hlp
->id_name
<< " #" << srv
->index
<< " is RESERVED. Closing anyway.");
685 debugs(84, 3, "helperStatefulShutdown: " << hlp
->id_name
<< " #" << srv
->index
<< " is RESERVED. Not Shutting Down Yet.");
690 debugs(84, 3, "helperStatefulShutdown: " << hlp
->id_name
<< " #" << srv
->index
<< " shutting down.");
692 /* the rest of the details is dealt with in the helperStatefulServerFree
695 srv
->closePipesSafely(hlp
->id_name
);
701 /* note, don't free id_name, it probably points to static memory */
703 // TODO: if the queue is not empty it will leak Helper::Request's
705 debugs(84, DBG_CRITICAL
, "WARNING: freeing " << id_name
<< " helper with " << stats
.queue_size
<< " requests queued");
708 /* ====================================================================== */
709 /* LOCAL FUNCTIONS */
710 /* ====================================================================== */
713 helperServerFree(helper_server
*srv
)
715 helper
*hlp
= srv
->parent
;
716 int concurrency
= hlp
->childs
.concurrency
;
722 memFreeBuf(srv
->rbuf_sz
, srv
->rbuf
);
726 srv
->wqueue
->clean();
730 srv
->writebuf
->clean();
731 delete srv
->writebuf
;
732 srv
->writebuf
= NULL
;
735 if (Comm::IsConnOpen(srv
->writePipe
))
736 srv
->closeWritePipeSafely(hlp
->id_name
);
738 dlinkDelete(&srv
->link
, &hlp
->servers
);
740 assert(hlp
->childs
.n_running
> 0);
741 -- hlp
->childs
.n_running
;
743 if (!srv
->flags
.shutdown
) {
744 assert(hlp
->childs
.n_active
> 0);
745 -- hlp
->childs
.n_active
;
746 debugs(84, DBG_CRITICAL
, "WARNING: " << hlp
->id_name
<< " #" << srv
->index
<< " exited");
748 if (hlp
->childs
.needNew() > 0) {
749 debugs(80, DBG_IMPORTANT
, "Too few " << hlp
->id_name
<< " processes are running (need " << hlp
->childs
.needNew() << "/" << hlp
->childs
.n_max
<< ")");
751 if (hlp
->childs
.n_active
< hlp
->childs
.n_startup
&& hlp
->last_restart
> squid_curtime
- 30) {
752 if (srv
->stats
.replies
< 1)
753 fatalf("The %s helpers are crashing too rapidly, need help!\n", hlp
->id_name
);
755 debugs(80, DBG_CRITICAL
, "ERROR: The " << hlp
->id_name
<< " helpers are crashing too rapidly, need help!");
758 debugs(80, DBG_IMPORTANT
, "Starting new helpers");
759 helperOpenServers(hlp
);
763 while (!srv
->requests
.empty()) {
764 // XXX: re-schedule these on another helper?
765 Helper::Xaction
*r
= srv
->requests
.front();
766 srv
->requests
.pop_front();
769 if (cbdataReferenceValidDone(r
->request
.data
, &cbdata
)) {
770 r
->reply
.result
= Helper::Unknown
;
771 r
->request
.callback(cbdata
, r
->reply
);
776 srv
->requestsIndex
.clear();
778 cbdataReferenceDone(srv
->parent
);
783 helperStatefulServerFree(helper_stateful_server
*srv
)
785 statefulhelper
*hlp
= srv
->parent
;
788 memFreeBuf(srv
->rbuf_sz
, srv
->rbuf
);
793 srv
->wqueue
->clean();
799 /* TODO: walk the local queue of requests and carry them all out */
800 if (Comm::IsConnOpen(srv
->writePipe
))
801 srv
->closeWritePipeSafely(hlp
->id_name
);
803 dlinkDelete(&srv
->link
, &hlp
->servers
);
805 assert(hlp
->childs
.n_running
> 0);
806 -- hlp
->childs
.n_running
;
808 if (!srv
->flags
.shutdown
) {
809 assert( hlp
->childs
.n_active
> 0);
810 -- hlp
->childs
.n_active
;
811 debugs(84, DBG_CRITICAL
, "WARNING: " << hlp
->id_name
<< " #" << srv
->index
<< " exited");
813 if (hlp
->childs
.needNew() > 0) {
814 debugs(80, DBG_IMPORTANT
, "Too few " << hlp
->id_name
<< " processes are running (need " << hlp
->childs
.needNew() << "/" << hlp
->childs
.n_max
<< ")");
816 if (hlp
->childs
.n_active
< hlp
->childs
.n_startup
&& hlp
->last_restart
> squid_curtime
- 30) {
817 if (srv
->stats
.replies
< 1)
818 fatalf("The %s helpers are crashing too rapidly, need help!\n", hlp
->id_name
);
820 debugs(80, DBG_CRITICAL
, "ERROR: The " << hlp
->id_name
<< " helpers are crashing too rapidly, need help!");
823 debugs(80, DBG_IMPORTANT
, "Starting new helpers");
824 helperStatefulOpenServers(hlp
);
828 while (!srv
->requests
.empty()) {
829 // XXX: re-schedule these on another helper?
830 Helper::Xaction
*r
= srv
->requests
.front();
831 srv
->requests
.pop_front();
834 if (cbdataReferenceValidDone(r
->request
.data
, &cbdata
)) {
835 r
->reply
.result
= Helper::Unknown
;
836 r
->request
.callback(cbdata
, r
->reply
);
842 cbdataReferenceDone(srv
->parent
);
848 helper_server::popRequest(int request_number
)
850 Helper::Xaction
*r
= nullptr;
851 helper_server::RequestIndex::iterator it
;
852 if (parent
->childs
.concurrency
) {
853 // If concurency supported retrieve request from ID
854 it
= requestsIndex
.find(request_number
);
855 if (it
!= requestsIndex
.end()) {
857 requests
.erase(it
->second
);
858 requestsIndex
.erase(it
);
860 } else if(!requests
.empty()) {
861 // Else get the first request from queue, if any
862 r
= requests
.front();
863 requests
.pop_front();
869 /// Calls back with a pointer to the buffer with the helper output
871 helperReturnBuffer(helper_server
* srv
, helper
* hlp
, char * msg
, size_t msgSize
, char * msgEnd
)
873 if (Helper::Xaction
*r
= srv
->replyXaction
) {
874 const bool hasSpace
= r
->reply
.accumulate(msg
, msgSize
);
876 debugs(84, DBG_IMPORTANT
, "ERROR: Disconnecting from a " <<
877 "helper that overflowed " << srv
->rbuf_sz
<< "-byte " <<
878 "Squid input buffer: " << hlp
->id_name
<< " #" << srv
->index
);
879 srv
->closePipesSafely(hlp
->id_name
);
884 return; // We are waiting for more data.
887 if (cbdataReferenceValid(r
->request
.data
)) {
889 if (r
->reply
.result
== Helper::BrokenHelper
&& r
->request
.retries
< MAX_RETRIES
) {
890 debugs(84, DBG_IMPORTANT
, "ERROR: helper: " << r
->reply
<< ", attempt #" << (r
->request
.retries
+ 1) << " of 2");
893 HLPCB
*callback
= r
->request
.callback
;
894 r
->request
.callback
= nullptr;
895 void *cbdata
= nullptr;
896 if (cbdataReferenceValidDone(r
->request
.data
, &cbdata
))
897 callback(cbdata
, r
->reply
);
901 -- srv
->stats
.pending
;
902 ++ srv
->stats
.replies
;
904 ++ hlp
->stats
.replies
;
906 srv
->answer_time
= current_time
;
908 srv
->dispatch_time
= r
->request
.dispatch_time
;
910 hlp
->stats
.avg_svc_time
=
911 Math::intAverage(hlp
->stats
.avg_svc_time
,
912 tvSubMsec(r
->request
.dispatch_time
, current_time
),
913 hlp
->stats
.replies
, REDIRECT_AV_FACTOR
);
915 // release or re-submit parsedRequestXaction object
916 srv
->replyXaction
= nullptr;
918 ++r
->request
.retries
;
919 hlp
->submitRequest(r
);
924 if (hlp
->timeout
&& hlp
->childs
.concurrency
)
925 srv
->checkForTimedOutRequests(hlp
->retryTimedOut
);
927 if (!srv
->flags
.shutdown
) {
928 helperKickQueue(hlp
);
929 } else if (!srv
->flags
.closing
&& !srv
->stats
.pending
) {
930 srv
->flags
.closing
=true;
931 srv
->writePipe
->close();
936 helperHandleRead(const Comm::ConnectionPointer
&conn
, char *, size_t len
, Comm::Flag flag
, int, void *data
)
938 helper_server
*srv
= (helper_server
*)data
;
939 helper
*hlp
= srv
->parent
;
940 assert(cbdataReferenceValid(data
));
942 /* Bail out early on Comm::ERR_CLOSING - close handlers will tidy up for us */
944 if (flag
== Comm::ERR_CLOSING
) {
948 assert(conn
->fd
== srv
->readPipe
->fd
);
950 debugs(84, 5, "helperHandleRead: " << len
<< " bytes from " << hlp
->id_name
<< " #" << srv
->index
);
952 if (flag
!= Comm::OK
|| len
== 0) {
953 srv
->closePipesSafely(hlp
->id_name
);
958 srv
->rbuf
[srv
->roffset
] = '\0';
959 debugs(84, DBG_DATA
, Raw("accumulated", srv
->rbuf
, srv
->roffset
));
961 if (!srv
->stats
.pending
&& !srv
->stats
.timedout
) {
962 /* someone spoke without being spoken to */
963 debugs(84, DBG_IMPORTANT
, "helperHandleRead: unexpected read from " <<
964 hlp
->id_name
<< " #" << srv
->index
<< ", " << (int)len
<<
965 " bytes '" << srv
->rbuf
<< "'");
971 bool needsMore
= false;
972 char *msg
= srv
->rbuf
;
973 while (*msg
&& !needsMore
) {
975 char *eom
= strchr(msg
, hlp
->eom
);
978 debugs(84, 3, "helperHandleRead: end of reply found");
979 if (eom
> msg
&& eom
[-1] == '\r' && hlp
->eom
== '\n') {
981 // rewind to the \r octet which is the real terminal now
982 // and remember that we have to skip forward 2 places now.
989 if (!srv
->ignoreToEom
&& !srv
->replyXaction
) {
991 if (hlp
->childs
.concurrency
) {
993 i
= strtol(msg
, &e
, 10);
994 // Do we need to check for e == msg? Means wrong response from helper.
995 // Will be droped as "unexpected reply on channel 0"
996 needsMore
= !(xisspace(*e
) || (eom
&& e
== eom
));
999 while (*msg
&& xisspace(*msg
))
1001 } // else not enough data to compute request number
1003 if (!(srv
->replyXaction
= srv
->popRequest(i
))) {
1004 if (srv
->stats
.timedout
) {
1005 debugs(84, 3, "Timedout reply received for request-ID: " << i
<< " , ignore");
1007 debugs(84, DBG_IMPORTANT
, "helperHandleRead: unexpected reply on channel " <<
1008 i
<< " from " << hlp
->id_name
<< " #" << srv
->index
<<
1009 " '" << srv
->rbuf
<< "'");
1011 srv
->ignoreToEom
= true;
1013 } // else we need to just append reply data to the current Xaction
1016 size_t msgSize
= eom
? eom
- msg
: (srv
->roffset
- (msg
- srv
->rbuf
));
1017 assert(msgSize
<= srv
->rbuf_sz
);
1018 helperReturnBuffer(srv
, hlp
, msg
, msgSize
, eom
);
1019 msg
+= msgSize
+ skip
;
1020 assert(static_cast<size_t>(msg
- srv
->rbuf
) <= srv
->rbuf_sz
);
1022 // The next message should not ignored.
1023 if (eom
&& srv
->ignoreToEom
)
1024 srv
->ignoreToEom
= false;
1026 assert(skip
== 0 && eom
== NULL
);
1030 size_t msgSize
= (srv
->roffset
- (msg
- srv
->rbuf
));
1031 assert(msgSize
<= srv
->rbuf_sz
);
1032 memmove(srv
->rbuf
, msg
, msgSize
);
1033 srv
->roffset
= msgSize
;
1034 srv
->rbuf
[srv
->roffset
] = '\0';
1036 // All of the responses parsed and msg points at the end of read data
1037 assert(static_cast<size_t>(msg
- srv
->rbuf
) == srv
->roffset
);
1041 if (Comm::IsConnOpen(srv
->readPipe
) && !fd_table
[srv
->readPipe
->fd
].closing()) {
1042 int spaceSize
= srv
->rbuf_sz
- srv
->roffset
- 1;
1043 assert(spaceSize
>= 0);
1045 AsyncCall::Pointer call
= commCbCall(5,4, "helperHandleRead",
1046 CommIoCbPtrFun(helperHandleRead
, srv
));
1047 comm_read(srv
->readPipe
, srv
->rbuf
+ srv
->roffset
, spaceSize
, call
);
1052 helperStatefulHandleRead(const Comm::ConnectionPointer
&conn
, char *, size_t len
, Comm::Flag flag
, int, void *data
)
1055 helper_stateful_server
*srv
= (helper_stateful_server
*)data
;
1056 statefulhelper
*hlp
= srv
->parent
;
1057 assert(cbdataReferenceValid(data
));
1059 /* Bail out early on Comm::ERR_CLOSING - close handlers will tidy up for us */
1061 if (flag
== Comm::ERR_CLOSING
) {
1065 assert(conn
->fd
== srv
->readPipe
->fd
);
1067 debugs(84, 5, "helperStatefulHandleRead: " << len
<< " bytes from " <<
1068 hlp
->id_name
<< " #" << srv
->index
);
1070 if (flag
!= Comm::OK
|| len
== 0) {
1071 srv
->closePipesSafely(hlp
->id_name
);
1075 srv
->roffset
+= len
;
1076 srv
->rbuf
[srv
->roffset
] = '\0';
1077 Helper::Xaction
*r
= srv
->requests
.front();
1078 debugs(84, DBG_DATA
, Raw("accumulated", srv
->rbuf
, srv
->roffset
));
1081 /* someone spoke without being spoken to */
1082 debugs(84, DBG_IMPORTANT
, "helperStatefulHandleRead: unexpected read from " <<
1083 hlp
->id_name
<< " #" << srv
->index
<< ", " << (int)len
<<
1084 " bytes '" << srv
->rbuf
<< "'");
1089 if ((t
= strchr(srv
->rbuf
, hlp
->eom
))) {
1090 debugs(84, 3, "helperStatefulHandleRead: end of reply found");
1092 if (t
> srv
->rbuf
&& t
[-1] == '\r' && hlp
->eom
== '\n') {
1094 // rewind to the \r octet which is the real terminal now
1101 if (r
&& !r
->reply
.accumulate(srv
->rbuf
, t
? (t
- srv
->rbuf
) : srv
->roffset
)) {
1102 debugs(84, DBG_IMPORTANT
, "ERROR: Disconnecting from a " <<
1103 "helper that overflowed " << srv
->rbuf_sz
<< "-byte " <<
1104 "Squid input buffer: " << hlp
->id_name
<< " #" << srv
->index
);
1105 srv
->closePipesSafely(hlp
->id_name
);
1109 * BUG: the below assumes that only one response per read() was received and discards any octets remaining.
1110 * Doing this prohibits concurrency support with multiple replies per read().
1111 * TODO: check that read() setup on these buffers pays attention to roffest!=0
1112 * TODO: check that replies bigger than the buffer are discarded and do not to affect future replies
1117 /* end of reply found */
1118 srv
->requests
.pop_front(); // we already have it in 'r'
1121 if (r
&& cbdataReferenceValid(r
->request
.data
)) {
1122 r
->reply
.finalize();
1123 r
->reply
.whichServer
= srv
;
1124 r
->request
.callback(r
->request
.data
, r
->reply
);
1126 debugs(84, DBG_IMPORTANT
, "StatefulHandleRead: no callback data registered");
1132 -- srv
->stats
.pending
;
1133 ++ srv
->stats
.replies
;
1135 ++ hlp
->stats
.replies
;
1136 srv
->answer_time
= current_time
;
1137 hlp
->stats
.avg_svc_time
=
1138 Math::intAverage(hlp
->stats
.avg_svc_time
,
1139 tvSubMsec(srv
->dispatch_time
, current_time
),
1140 hlp
->stats
.replies
, REDIRECT_AV_FACTOR
);
1143 helperStatefulServerDone(srv
);
1145 helperStatefulReleaseServer(srv
);
1148 if (Comm::IsConnOpen(srv
->readPipe
) && !fd_table
[srv
->readPipe
->fd
].closing()) {
1149 int spaceSize
= srv
->rbuf_sz
- 1;
1151 AsyncCall::Pointer call
= commCbCall(5,4, "helperStatefulHandleRead",
1152 CommIoCbPtrFun(helperStatefulHandleRead
, srv
));
1153 comm_read(srv
->readPipe
, srv
->rbuf
, spaceSize
, call
);
1157 /// Handles a request when all running helpers, if any, are busy.
1159 Enqueue(helper
* hlp
, Helper::Xaction
* r
)
1162 ++ hlp
->stats
.queue_size
;
1164 /* do this first so idle=N has a chance to grow the child pool before it hits critical. */
1165 if (hlp
->childs
.needNew() > 0) {
1166 debugs(84, DBG_CRITICAL
, "Starting new " << hlp
->id_name
<< " helpers...");
1167 helperOpenServers(hlp
);
1171 if (hlp
->stats
.queue_size
< (int)hlp
->childs
.queue_size
)
1174 if (squid_curtime
- hlp
->last_queue_warn
< 600)
1177 if (shutting_down
|| reconfiguring
)
1180 hlp
->last_queue_warn
= squid_curtime
;
1182 debugs(84, DBG_CRITICAL
, "WARNING: All " << hlp
->childs
.n_active
<< "/" << hlp
->childs
.n_max
<< " " << hlp
->id_name
<< " processes are busy.");
1183 debugs(84, DBG_CRITICAL
, "WARNING: " << hlp
->stats
.queue_size
<< " pending requests queued");
1184 debugs(84, DBG_CRITICAL
, "WARNING: Consider increasing the number of " << hlp
->id_name
<< " processes in your config file.");
1188 StatefulEnqueue(statefulhelper
* hlp
, Helper::Xaction
* r
)
1191 ++ hlp
->stats
.queue_size
;
1193 /* do this first so idle=N has a chance to grow the child pool before it hits critical. */
1194 if (hlp
->childs
.needNew() > 0) {
1195 debugs(84, DBG_CRITICAL
, "Starting new " << hlp
->id_name
<< " helpers...");
1196 helperStatefulOpenServers(hlp
);
1200 if (hlp
->stats
.queue_size
< (int)hlp
->childs
.queue_size
)
1203 if (squid_curtime
- hlp
->last_queue_warn
< 600)
1206 if (shutting_down
|| reconfiguring
)
1209 hlp
->last_queue_warn
= squid_curtime
;
1211 debugs(84, DBG_CRITICAL
, "WARNING: All " << hlp
->childs
.n_active
<< "/" << hlp
->childs
.n_max
<< " " << hlp
->id_name
<< " processes are busy.");
1212 debugs(84, DBG_CRITICAL
, "WARNING: " << hlp
->stats
.queue_size
<< " pending requests queued");
1213 debugs(84, DBG_CRITICAL
, "WARNING: Consider increasing the number of " << hlp
->id_name
<< " processes in your config file.");
1217 helper::nextRequest()
1222 auto *r
= queue
.front();
1228 static helper_server
*
1229 GetFirstAvailable(const helper
* hlp
)
1233 helper_server
*selected
= NULL
;
1234 debugs(84, 5, "GetFirstAvailable: Running servers " << hlp
->childs
.n_running
);
1236 if (hlp
->childs
.n_running
== 0)
1239 /* Find "least" loaded helper (approx) */
1240 for (n
= hlp
->servers
.head
; n
!= NULL
; n
= n
->next
) {
1241 srv
= (helper_server
*)n
->data
;
1243 if (selected
&& selected
->stats
.pending
<= srv
->stats
.pending
)
1246 if (srv
->flags
.shutdown
)
1249 if (!srv
->stats
.pending
)
1261 debugs(84, 5, "GetFirstAvailable: None available.");
1265 if (selected
->stats
.pending
>= (hlp
->childs
.concurrency
? hlp
->childs
.concurrency
: 1)) {
1266 debugs(84, 3, "GetFirstAvailable: Least-loaded helper is fully loaded!");
1270 debugs(84, 5, "GetFirstAvailable: returning srv-" << selected
->index
);
1274 static helper_stateful_server
*
1275 StatefulGetFirstAvailable(const statefulhelper
* hlp
)
1278 helper_stateful_server
*srv
= NULL
;
1279 debugs(84, 5, "StatefulGetFirstAvailable: Running servers " << hlp
->childs
.n_running
);
1281 if (hlp
->childs
.n_running
== 0)
1284 for (n
= hlp
->servers
.head
; n
!= NULL
; n
= n
->next
) {
1285 srv
= (helper_stateful_server
*)n
->data
;
1287 if (srv
->stats
.pending
)
1290 if (srv
->flags
.reserved
)
1293 if (srv
->flags
.shutdown
)
1296 debugs(84, 5, "StatefulGetFirstAvailable: returning srv-" << srv
->index
);
1300 debugs(84, 5, "StatefulGetFirstAvailable: None available.");
1305 helperDispatchWriteDone(const Comm::ConnectionPointer
&, char *, size_t, Comm::Flag flag
, int, void *data
)
1307 helper_server
*srv
= (helper_server
*)data
;
1309 srv
->writebuf
->clean();
1310 delete srv
->writebuf
;
1311 srv
->writebuf
= NULL
;
1312 srv
->flags
.writing
= false;
1314 if (flag
!= Comm::OK
) {
1315 /* Helper server has crashed */
1316 debugs(84, DBG_CRITICAL
, "helperDispatch: Helper " << srv
->parent
->id_name
<< " #" << srv
->index
<< " has crashed");
1320 if (!srv
->wqueue
->isNull()) {
1321 srv
->writebuf
= srv
->wqueue
;
1322 srv
->wqueue
= new MemBuf
;
1323 srv
->flags
.writing
= true;
1324 AsyncCall::Pointer call
= commCbCall(5,5, "helperDispatchWriteDone",
1325 CommIoCbPtrFun(helperDispatchWriteDone
, srv
));
1326 Comm::Write(srv
->writePipe
, srv
->writebuf
->content(), srv
->writebuf
->contentSize(), call
, NULL
);
1331 helperDispatch(helper_server
* srv
, Helper::Xaction
* r
)
1333 helper
*hlp
= srv
->parent
;
1334 const uint64_t reqId
= ++srv
->nextRequestId
;
1336 if (!cbdataReferenceValid(r
->request
.data
)) {
1337 debugs(84, DBG_IMPORTANT
, "helperDispatch: invalid callback data");
1342 r
->request
.Id
= reqId
;
1343 helper_server::Requests::iterator it
= srv
->requests
.insert(srv
->requests
.end(), r
);
1344 r
->request
.dispatch_time
= current_time
;
1346 if (srv
->wqueue
->isNull())
1347 srv
->wqueue
->init();
1349 if (hlp
->childs
.concurrency
) {
1350 srv
->requestsIndex
.insert(helper_server::RequestIndex::value_type(reqId
, it
));
1351 assert(srv
->requestsIndex
.size() == srv
->requests
.size());
1352 srv
->wqueue
->appendf("%" PRIu64
" %s", reqId
, r
->request
.buf
);
1354 srv
->wqueue
->append(r
->request
.buf
, strlen(r
->request
.buf
));
1356 if (!srv
->flags
.writing
) {
1357 assert(NULL
== srv
->writebuf
);
1358 srv
->writebuf
= srv
->wqueue
;
1359 srv
->wqueue
= new MemBuf
;
1360 srv
->flags
.writing
= true;
1361 AsyncCall::Pointer call
= commCbCall(5,5, "helperDispatchWriteDone",
1362 CommIoCbPtrFun(helperDispatchWriteDone
, srv
));
1363 Comm::Write(srv
->writePipe
, srv
->writebuf
->content(), srv
->writebuf
->contentSize(), call
, NULL
);
1366 debugs(84, 5, "helperDispatch: Request sent to " << hlp
->id_name
<< " #" << srv
->index
<< ", " << strlen(r
->request
.buf
) << " bytes");
1369 ++ srv
->stats
.pending
;
1370 ++ hlp
->stats
.requests
;
1374 helperStatefulDispatchWriteDone(const Comm::ConnectionPointer
&, char *, size_t, Comm::Flag
, int, void *)
1378 helperStatefulDispatch(helper_stateful_server
* srv
, Helper::Xaction
* r
)
1380 statefulhelper
*hlp
= srv
->parent
;
1382 if (!cbdataReferenceValid(r
->request
.data
)) {
1383 debugs(84, DBG_IMPORTANT
, "helperStatefulDispatch: invalid callback data");
1385 helperStatefulReleaseServer(srv
);
1389 debugs(84, 9, "helperStatefulDispatch busying helper " << hlp
->id_name
<< " #" << srv
->index
);
1391 if (r
->request
.placeholder
== 1) {
1392 /* a callback is needed before this request can _use_ a helper. */
1393 /* we don't care about releasing this helper. The request NEVER
1394 * gets to the helper. So we throw away the return code */
1395 r
->reply
.result
= Helper::Unknown
;
1396 r
->reply
.whichServer
= srv
;
1397 r
->request
.callback(r
->request
.data
, r
->reply
);
1398 /* throw away the placeholder */
1400 /* and push the queue. Note that the callback may have submitted a new
1401 * request to the helper which is why we test for the request */
1403 if (!srv
->requests
.size())
1404 helperStatefulServerDone(srv
);
1409 srv
->flags
.reserved
= true;
1410 srv
->requests
.push_back(r
);
1411 srv
->dispatch_time
= current_time
;
1412 AsyncCall::Pointer call
= commCbCall(5,5, "helperStatefulDispatchWriteDone",
1413 CommIoCbPtrFun(helperStatefulDispatchWriteDone
, hlp
));
1414 Comm::Write(srv
->writePipe
, r
->request
.buf
, strlen(r
->request
.buf
), call
, NULL
);
1415 debugs(84, 5, "helperStatefulDispatch: Request sent to " <<
1416 hlp
->id_name
<< " #" << srv
->index
<< ", " <<
1417 (int) strlen(r
->request
.buf
) << " bytes");
1420 ++ srv
->stats
.pending
;
1421 ++ hlp
->stats
.requests
;
1425 helperKickQueue(helper
* hlp
)
1430 while ((srv
= GetFirstAvailable(hlp
)) && (r
= hlp
->nextRequest()))
1431 helperDispatch(srv
, r
);
1435 helperStatefulKickQueue(statefulhelper
* hlp
)
1438 helper_stateful_server
*srv
;
1440 while ((srv
= StatefulGetFirstAvailable(hlp
)) && (r
= hlp
->nextRequest()))
1441 helperStatefulDispatch(srv
, r
);
1445 helperStatefulServerDone(helper_stateful_server
* srv
)
1447 if (!srv
->flags
.shutdown
) {
1448 helperStatefulKickQueue(srv
->parent
);
1449 } else if (!srv
->flags
.closing
&& !srv
->flags
.reserved
&& !srv
->stats
.pending
) {
1450 srv
->closeWritePipeSafely(srv
->parent
->id_name
);
1456 helper_server::checkForTimedOutRequests(bool const retry
)
1458 assert(parent
->childs
.concurrency
);
1459 while(!requests
.empty() && requests
.front()->request
.timedOut(parent
->timeout
)) {
1460 Helper::Xaction
*r
= requests
.front();
1461 RequestIndex::iterator it
;
1462 it
= requestsIndex
.find(r
->request
.Id
);
1463 assert(it
!= requestsIndex
.end());
1464 requestsIndex
.erase(it
);
1465 requests
.pop_front();
1466 debugs(84, 2, "Request " << r
->request
.Id
<< " timed-out, remove it from queue");
1468 bool retried
= false;
1469 if (retry
&& r
->request
.retries
< MAX_RETRIES
&& cbdataReferenceValid(r
->request
.data
)) {
1470 debugs(84, 2, "Retry request " << r
->request
.Id
);
1471 ++r
->request
.retries
;
1472 parent
->submitRequest(r
);
1474 } else if (cbdataReferenceValidDone(r
->request
.data
, &cbdata
)) {
1475 if (!parent
->onTimedOutResponse
.isEmpty()) {
1476 if (r
->reply
.accumulate(parent
->onTimedOutResponse
.rawContent(), parent
->onTimedOutResponse
.length()))
1477 r
->reply
.finalize();
1479 r
->reply
.result
= Helper::TimedOut
;
1480 r
->request
.callback(cbdata
, r
->reply
);
1482 r
->reply
.result
= Helper::TimedOut
;
1483 r
->request
.callback(cbdata
, r
->reply
);
1488 ++parent
->stats
.timedout
;
1495 helper_server::requestTimeout(const CommTimeoutCbParams
&io
)
1497 debugs(26, 3, HERE
<< io
.conn
);
1498 helper_server
*srv
= static_cast<helper_server
*>(io
.data
);
1500 if (!cbdataReferenceValid(srv
))
1503 srv
->checkForTimedOutRequests(srv
->parent
->retryTimedOut
);
1505 debugs(84, 3, HERE
<< io
.conn
<< " establish new helper_server::requestTimeout");
1506 AsyncCall::Pointer timeoutCall
= commCbCall(84, 4, "helper_server::requestTimeout",
1507 CommTimeoutCbPtrFun(helper_server::requestTimeout
, srv
));
1509 const int timeSpent
= srv
->requests
.empty() ? 0 : (squid_curtime
- srv
->requests
.front()->request
.dispatch_time
.tv_sec
);
1510 const int timeLeft
= max(1, (static_cast<int>(srv
->parent
->timeout
) - timeSpent
));
1512 commSetConnTimeout(io
.conn
, timeLeft
, timeoutCall
);