Skip to content

Commit c9e5fb7

Browse files
authored
Return captive_action from HttpCachSM if read retry event is scheduled (#12313)
1 parent 6e812e3 commit c9e5fb7

3 files changed

Lines changed: 18 additions & 14 deletions

File tree

include/proxy/http/HttpCacheSM.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ class HttpCacheSM : public Continuation
8686
captive_action.init(this);
8787
}
8888
void reset();
89-
void cleanup();
89+
void cancel_pending_action();
9090

9191
Action *open_read(const HttpCacheKey *key, URL *url, HTTPHdr *hdr, const OverridableHttpConfigParams *params,
9292
time_t pin_in_cache);

src/proxy/http/HttpCacheSM.cc

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,7 @@ HttpCacheAction::cancel(Continuation *c)
5555
ink_assert(this->cancelled == false);
5656

5757
this->cancelled = true;
58-
if (_cache_sm->pending_action) {
59-
_cache_sm->pending_action->cancel();
60-
}
58+
_cache_sm->cancel_pending_action();
6159
}
6260

6361
////
@@ -74,12 +72,16 @@ HttpCacheSM::reset()
7472
}
7573

7674
void
77-
HttpCacheSM::cleanup()
75+
HttpCacheSM::cancel_pending_action()
7876
{
79-
ink_release_assert(this->mutex && this->mutex->thread_holding == this_ethread());
77+
if (pending_action != nullptr) {
78+
pending_action->cancel();
79+
pending_action = nullptr;
80+
}
8081

8182
if (_read_retry_event != nullptr) {
8283
_read_retry_event->cancel();
84+
_read_retry_event = nullptr;
8385
}
8486
}
8587

@@ -329,10 +331,11 @@ HttpCacheSM::do_cache_open_read(const HttpCacheKey &key)
329331
} else {
330332
// In some cases, CacheProcessor::open_read calls back to `state_cache_open_read` with a cache event. If the event is
331333
// CACHE_EVENT_OPEN_READ_FAILED, a read retry event might be scheduled. In this case, CacheProcessor::open_read returns
332-
// ACTION_RESULT_DONE, even though the read retry event is still pending. To indicate this situation to HttpSM, the scheduled
333-
// read retry event is returned. HttpSM can cancel the event if necessary.
334+
// ACTION_RESULT_DONE, even though the read retry event is still pending. To indicate this situation to HttpSM, `captive_action`
335+
// is returned. HttpSM can cancel the event though this `captive_action` if necessary.
334336
if (_read_retry_event && _read_retry_event->cancelled != true) {
335-
return _read_retry_event;
337+
captive_action.cancelled = false;
338+
return &captive_action;
336339
} else {
337340
return ACTION_RESULT_DONE;
338341
}
@@ -423,11 +426,12 @@ HttpCacheSM::open_write(const HttpCacheKey *key, URL *url, HTTPHdr *request, Cac
423426
return &captive_action;
424427
} else {
425428
// In some cases, CacheProcessor::open_write calls back to `state_cache_open_write` with a cache event. If the event is
426-
// CACHE_EVENT_OPEN_WRITE_FAILED, a read retry event might be scheduled. In this case, CacheProcessor::open_read returns
427-
// ACTION_RESULT_DONE, even though the read retry event is still pending. To indicate this situation to HttpSM, the scheduled
428-
// read retry event is returned. HttpSM can cancel the event if necessary.
429+
// CACHE_EVENT_OPEN_WRITE_FAILED, a read retry event might be scheduled. In this case, CacheProcessor::open_write returns
430+
// ACTION_RESULT_DONE, even though the read retry event is still pending. To indicate this situation to HttpSM, `captive_action`
431+
// is returned. HttpSM can cancel the event though this `captive_action` if necessary.
429432
if (_read_retry_event && _read_retry_event->cancelled != true) {
430-
return _read_retry_event;
433+
captive_action.cancelled = false;
434+
return &captive_action;
431435
} else {
432436
return ACTION_RESULT_DONE;
433437
}

src/proxy/http/HttpSM.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,7 @@ HttpSM::cleanup()
260260
HttpConfig::release(t_state.http_config_param);
261261
m_remap->release();
262262

263-
cache_sm.cleanup();
263+
cache_sm.cancel_pending_action();
264264

265265
mutex.clear();
266266
tunnel.mutex.clear();

0 commit comments

Comments
 (0)