Continuations
This chapter covers the following topics:
A continuation must be created with a mutex if your continuation does one of the following:
- is registered globally (
TSHttpHookAdd
orTSHttpSsnHookAdd
) to an HTTP hook and usesTSContDataSet/Get
- uses
TSCacheXXX
,TSNetXXX
, , orTSContSchedule
APIs
A reentrant call occurs when the continuation passed as an argument to the API can be called in the same stack trace as the function calling the API. For example, if you call TSCacheRead
(contp, mykey
), it is possible that contp
’s handler will be called directly and then TSCacheRead
returns.
Caveats that could cause issues include the following:
- a continuation has data associated with it (
TSContDataGet
). - the reentrant call passes itself as a continuation to the reentrant API. In this case, the continuation should not try to access its data after calling the reentrant API. The reason for this is that data may be modified by the section of code in the continuation’s handler that handles the event sent by the API. It is recommended that you always return after a reentrant call to avoid accessing something that has been deallocated.
The above example first assumes that the continuation is called back with ; it then does the first reentrant call that schedules the continuation to receive event2
. Because the call is reentrant, the processor calls back the continuation right away with event2
and the continuation is destroyed. If you try to access the continuation or one of its members after the reentrant call, then you might access something that has been deallocated. To avoid accessing something that has been deallocated, never access the continuation or any of its members after a reentrant call - just exit the handler.
Note: Most HTTP transaction plugin continuations do not need non-null mutexes because they’re called within the processing of an HTTP transaction, and therefore have the transaction’s mutex.
When using a NULL
mutex it is dangerous to access the continuation’s data, but usually continuations with NULL
mutexes have no data associated with them anyway. An example of such a continuation is one that gets called back every time an HTTP request is read, and then determines from the request alone if the request should go through or be rejected. An HTTP transaction gives its continuation data to the .