Launcher.cc
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
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.
7  */
8 
9 /* DEBUG: section 93 ICAP (RFC 3507) Client */
10 
11 #include "squid.h"
12 #include "acl/FilledChecklist.h"
13 #include "adaptation/Answer.h"
14 #include "adaptation/icap/Config.h"
18 #include "base/TextException.h"
19 #include "globals.h"
20 #include "HttpReply.h"
21 
23  Adaptation::ServicePointer &aService):
24  AsyncJob(aTypeName),
25  Adaptation::Initiate(aTypeName),
26  theService(aService), theXaction(nullptr), theLaunches(0)
27 {
28 }
29 
31 {
32  assert(!theXaction);
33 }
34 
36 {
38 
39  Must(theInitiator.set());
40  launchXaction("first");
41 }
42 
44 {
45  Must(!theXaction);
46  ++theLaunches;
47  debugs(93,4, "launching " << xkind << " xaction #" << theLaunches);
48  Adaptation::Icap::Xaction *x = createXaction();
49  x->attempts = theLaunches;
50  if (theLaunches > 1) {
51  x->clearError();
52  x->disableRetries();
53  }
54  if (theLaunches >= TheConfig.repeat_limit)
55  x->disableRepeats("over icap_retry_limit");
56  theXaction = initiateAdaptation(x);
57  Must(initiated(theXaction));
58 }
59 
61 {
62  debugs(93,5, "launches: " << theLaunches << " answer: " << answer);
63 
64  // XXX: akError is unused by ICAPXaction in favor of noteXactAbort()
65  Must(answer.kind != Answer::akError);
66 
67  sendAnswer(answer);
68  clearAdaptation(theXaction);
69  Must(done());
70 }
71 
73 {
74 
75  announceInitiatorAbort(theXaction); // propagate to the transaction
76  clearInitiator();
77  Must(done()); // should be nothing else to do
78 
79 }
80 
82 {
83  debugs(93,5, "theXaction:" << theXaction << " launches: " << theLaunches);
84 
85  // TODO: add more checks from FwdState::checkRetry()?
86  if (canRetry(info)) {
87  clearAdaptation(theXaction);
88  launchXaction("retry");
89  } else if (canRepeat(info)) {
90  clearAdaptation(theXaction);
91  launchXaction("repeat");
92  } else {
93  debugs(93,3, "cannot retry or repeat a failed transaction");
94  clearAdaptation(theXaction);
95  tellQueryAborted(false); // caller decides based on bypass, consumption
96  Must(done());
97  }
98 }
99 
101 {
102  return (!theInitiator || !theXaction) && Adaptation::Initiate::doneAll();
103 }
104 
106 {
107  if (theInitiator.set())
108  tellQueryAborted(true); // always final here because abnormal
109 
110  if (theXaction.set())
111  clearAdaptation(theXaction);
112 
114 }
115 
117 {
118  // We do not check and can exceed zero repeat limit when retrying.
119  // This is by design as the limit does not apply to pconn retrying.
120  return !shutting_down && info.isRetriable;
121 }
122 
124 {
125  debugs(93,9, shutting_down);
126  if (theLaunches >= TheConfig.repeat_limit || shutting_down)
127  return false;
128 
129  debugs(93,9, info.isRepeatable); // TODO: update and use status()
130  if (!info.isRepeatable)
131  return false;
132 
133  debugs(93,9, info.icapReply);
134  if (!info.icapReply) // did not get to read an ICAP reply; a timeout?
135  return true;
136 
137  debugs(93,9, info.icapReply->sline.status());
138  // XXX: Http::scNone is not the only sign of parse error
139  // XXX: if there is a specific HTTP error code describing the problem, that may be set
140  if (info.icapReply->sline.status() == Http::scNone) // failed to parse the reply; I/O err
141  return true;
142 
144  cl.updateReply(info.icapReply);
145  return cl.fastCheck().allowed();
146 }
147 
148 /* ICAPXactAbortInfo */
149 
151  HttpReply *anIcapReply, bool beRetriable, bool beRepeatable):
152  icapRequest(anIcapRequest),
153  icapReply(anIcapReply),
154  isRetriable(beRetriable),
155  isRepeatable(beRepeatable)
156 {
157  if (icapRequest)
159  if (icapReply)
161 }
162 
164  icapRequest(i.icapRequest),
165  icapReply(i.icapReply),
166  isRetriable(i.isRetriable),
167  isRepeatable(i.isRepeatable)
168 {
169  if (icapRequest)
171  if (icapReply)
173 }
174 
176 {
177  HTTPMSGUNLOCK(icapRequest);
178  HTTPMSGUNLOCK(icapReply);
179 }
180 
XactAbortInfo(HttpRequest *anIcapRequest, HttpReply *anIcapReply, bool beRetriable, bool beRepeatable)
Definition: Launcher.cc:150
void noteInitiatorAborted() override
Definition: Launcher.cc:72
void swanSong() override
Definition: Initiate.cc:62
int attempts
the number of times we tried to get to the service, including this time
Definition: Xaction.h:67
Config TheConfig
Definition: Config.cc:19
@ scNone
Definition: StatusCode.h:21
void swanSong() override
Definition: Launcher.cc:105
bool doneAll() const override
whether positive goal has been reached
Definition: Launcher.cc:100
Http::StatusLine sline
Definition: HttpReply.h:56
void HTTPMSGUNLOCK(M *&a)
Definition: Message.h:150
void disableRepeats(const char *reason)
Definition: Xaction.cc:123
virtual void clearError()
clear stored error details, if any; used for retries/repeats
Definition: Xaction.h:118
bool canRetry(XactAbortInfo &info) const
Definition: Launcher.cc:116
void updateReply(const HttpReply::Pointer &)
void launchXaction(const char *xkind)
Definition: Launcher.cc:43
Launcher(const char *aTypeName, Adaptation::ServicePointer &aService)
Definition: Launcher.cc:22
int repeat_limit
icap_retry_limit in squid.conf
Definition: Config.h:39
virtual bool doneAll() const
whether positive goal has been reached
Definition: AsyncJob.cc:112
Http::StatusCode status() const
retrieve the status code for this status line
Definition: StatusLine.h:45
const Acl::Answer & fastCheck()
Definition: Checklist.cc:298
virtual void noteXactAbort(XactAbortInfo info)
Definition: Launcher.cc:81
Kind kind
the type of the answer
Definition: Answer.h:47
acl_access * repeat
icap_retry ACL in squid.conf
Definition: Config.h:38
#define assert(EX)
Definition: assert.h:17
void HTTPMSGLOCK(Http::Message *a)
Definition: Message.h:161
summarizes adaptation service answer for the noteAdaptationAnswer() API
Definition: Answer.h:24
void start() override
called by AsyncStart; do not call directly
Definition: Launcher.cc:35
bool allowed() const
Definition: Acl.h:82
@ akError
no adapted message will come; see bypassable
Definition: Answer.h:31
virtual void start()
called by AsyncStart; do not call directly
Definition: AsyncJob.cc:59
#define Must(condition)
Definition: TextException.h:75
int shutting_down
void noteAdaptationAnswer(const Answer &answer) override
Definition: Launcher.cc:60
bool canRepeat(XactAbortInfo &info) const
Definition: Launcher.cc:123
#define debugs(SECTION, LEVEL, CONTENT)
Definition: Stream.h:192

 

Introduction

Documentation

Support

Miscellaneous