diff --git a/doc/developer-guide/api/functions/TSActionCancel.en.rst b/doc/developer-guide/api/functions/TSActionCancel.en.rst index 1f8edd05305..abfb463fd26 100644 --- a/doc/developer-guide/api/functions/TSActionCancel.en.rst +++ b/doc/developer-guide/api/functions/TSActionCancel.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void TSActionCancel(TSAction actionp) +.. function:: void TSActionCancel(TSAction actionp) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSContDataGet.en.rst b/doc/developer-guide/api/functions/TSContDataGet.en.rst index 7c0e75498ea..fa9b83e49dd 100644 --- a/doc/developer-guide/api/functions/TSContDataGet.en.rst +++ b/doc/developer-guide/api/functions/TSContDataGet.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void* TSContDataGet(TSCont contp) +.. function:: void* TSContDataGet(TSCont contp) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSContDataSet.en.rst b/doc/developer-guide/api/functions/TSContDataSet.en.rst index 165fe30b97f..0a6ccf98b11 100644 --- a/doc/developer-guide/api/functions/TSContDataSet.en.rst +++ b/doc/developer-guide/api/functions/TSContDataSet.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void TSContDataSet(TSCont contp, void * data) +.. function:: void TSContDataSet(TSCont contp, void * data) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSContDestroy.en.rst b/doc/developer-guide/api/functions/TSContDestroy.en.rst index 12aa9bcfc65..e2b709043f9 100644 --- a/doc/developer-guide/api/functions/TSContDestroy.en.rst +++ b/doc/developer-guide/api/functions/TSContDestroy.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void TSContDestroy(TSCont contp) +.. function:: void TSContDestroy(TSCont contp) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSDebug.en.rst b/doc/developer-guide/api/functions/TSDebug.en.rst index d0b85efed8f..551b38b8c99 100644 --- a/doc/developer-guide/api/functions/TSDebug.en.rst +++ b/doc/developer-guide/api/functions/TSDebug.en.rst @@ -33,7 +33,7 @@ Synopsis .. function:: void TSStatus(const char * format, ...) .. function:: void TSNote(const char * format, ...) .. function:: void TSWarning(const char * format, ...) -.. function:: void TSError(const char * format, ...) +.. function:: void TSError(const char * format, ...) noexcept .. function:: void TSFatal(const char * format, ...) .. function:: void TSAlert(const char * format, ...) .. function:: void TSEmergency(const char * format, ...) diff --git a/doc/developer-guide/api/functions/TSFetchCreate.en.rst b/doc/developer-guide/api/functions/TSFetchCreate.en.rst index 67d0602fea2..fc31dc04f79 100644 --- a/doc/developer-guide/api/functions/TSFetchCreate.en.rst +++ b/doc/developer-guide/api/functions/TSFetchCreate.en.rst @@ -39,7 +39,7 @@ Synopsis .. function:: void TSFetchWriteData(TSFetchSM, const void *, size_t) .. function:: ssize_t TSFetchReadData(TSFetchSM, void *, size_t) .. function:: void TSFetchLaunch(TSFetchSM) -.. function:: void TSFetchDestroy(TSFetchSM) +.. function:: void TSFetchDestroy(TSFetchSM) noexcept .. function:: void TSFetchUserDataSet(TSFetchSM, void *) .. function:: void* TSFetchUserDataGet(TSFetchSM) .. function:: TSMBuffer TSFetchRespHdrMBufGet(TSFetchSM) diff --git a/doc/developer-guide/api/functions/TSHttpHdrDestroy.en.rst b/doc/developer-guide/api/functions/TSHttpHdrDestroy.en.rst index b40d6434efe..0bdbfc6de47 100644 --- a/doc/developer-guide/api/functions/TSHttpHdrDestroy.en.rst +++ b/doc/developer-guide/api/functions/TSHttpHdrDestroy.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void TSHttpHdrDestroy(TSMBuffer bufp, TSMLoc offset) +.. function:: void TSHttpHdrDestroy(TSMBuffer bufp, TSMLoc offset) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSHttpParserCreate.en.rst b/doc/developer-guide/api/functions/TSHttpParserCreate.en.rst index 62f45994a10..a56b193ee13 100644 --- a/doc/developer-guide/api/functions/TSHttpParserCreate.en.rst +++ b/doc/developer-guide/api/functions/TSHttpParserCreate.en.rst @@ -33,7 +33,7 @@ Synopsis .. function:: TSHttpParser TSHttpParserCreate(void) .. function:: void TSHttpParserClear(TSHttpParser parser) -.. function:: void TSHttpParserDestroy(TSHttpParser parser) +.. function:: void TSHttpParserDestroy(TSHttpParser parser) noexcept .. function:: TSParseResult TSHttpHdrParseReq(TSHttpParser parser, TSMBuffer bufp, TSMLoc offset, const char ** start, const char * end) .. function:: TSParseResult TSHttpHdrParseResp(TSHttpParser parser, TSMBuffer bufp, TSMLoc offset, const char ** start, const char * end) diff --git a/doc/developer-guide/api/functions/TSIOBufferCreate.en.rst b/doc/developer-guide/api/functions/TSIOBufferCreate.en.rst index de5d0a35d51..f84727cdf28 100644 --- a/doc/developer-guide/api/functions/TSIOBufferCreate.en.rst +++ b/doc/developer-guide/api/functions/TSIOBufferCreate.en.rst @@ -33,7 +33,7 @@ Synopsis .. function:: TSIOBuffer TSIOBufferCreate(void) .. function:: TSIOBuffer TSIOBufferSizedCreate(TSIOBufferSizeIndex index) -.. function:: void TSIOBufferDestroy(TSIOBuffer bufp) +.. function:: void TSIOBufferDestroy(TSIOBuffer bufp) noexcept .. function:: int64_t TSIOBufferWrite(TSIOBuffer bufp, const void * buf, int64_t length) .. function:: void TSIOBufferProduce(TSIOBuffer bufp, int64_t nbytes) .. function:: int64_t TSIOBufferWaterMarkGet(TSIOBuffer bufp) diff --git a/doc/developer-guide/api/functions/TSIOBufferReader.en.rst b/doc/developer-guide/api/functions/TSIOBufferReader.en.rst index 54434fa2cc1..44f44936d86 100644 --- a/doc/developer-guide/api/functions/TSIOBufferReader.en.rst +++ b/doc/developer-guide/api/functions/TSIOBufferReader.en.rst @@ -32,10 +32,10 @@ Synopsis .. function:: TSIOBufferReader TSIOBufferReaderAlloc(TSIOBuffer bufp) .. function:: TSIOBufferReader TSIOBufferReaderClone(TSIOBufferReader readerp) -.. function:: void TSIOBufferReaderFree(TSIOBufferReader readerp) -.. function:: void TSIOBufferReaderConsume(TSIOBufferReader readerp, int64_t nbytes) +.. function:: void TSIOBufferReaderFree(TSIOBufferReader readerp) noexcept +.. function:: void TSIOBufferReaderConsume(TSIOBufferReader readerp, int64_t nbytes) noexcept .. function:: TSIOBufferBlock TSIOBufferReaderStart(TSIOBufferReader readerp) -.. function:: int64_t TSIOBufferReaderAvail(TSIOBufferReader readerp) +.. function:: int64_t TSIOBufferReaderAvail(TSIOBufferReader readerp) noexcept .. function:: int64_t TSIOBufferReaderCopy(TSIOBufferReader reader, void * buf, int64_t length) Description diff --git a/doc/developer-guide/api/functions/TSMBufferCreate.en.rst b/doc/developer-guide/api/functions/TSMBufferCreate.en.rst index 36bdf0d8a51..4469965d6d0 100644 --- a/doc/developer-guide/api/functions/TSMBufferCreate.en.rst +++ b/doc/developer-guide/api/functions/TSMBufferCreate.en.rst @@ -30,8 +30,8 @@ Synopsis #include .. function:: TSMBuffer TSMBufferCreate(void) -.. function:: TSReturnCode TSMBufferDestroy(TSMBuffer bufp) -.. function:: TSReturnCode TSHandleMLocRelease(TSMBuffer bufp, TSMLoc parent, TSMLoc mloc) +.. function:: TSReturnCode TSMBufferDestroy(TSMBuffer bufp) noexcept +.. function:: TSReturnCode TSHandleMLocRelease(TSMBuffer bufp, TSMLoc parent, TSMLoc mloc) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSMimeHdrDestroy.en.rst b/doc/developer-guide/api/functions/TSMimeHdrDestroy.en.rst index 000f58dc9d1..f1a262db4d3 100644 --- a/doc/developer-guide/api/functions/TSMimeHdrDestroy.en.rst +++ b/doc/developer-guide/api/functions/TSMimeHdrDestroy.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: TSReturnCode TSMimeHdrDestroy(TSMBuffer bufp, TSMLoc offset) +.. function:: TSReturnCode TSMimeHdrDestroy(TSMBuffer bufp, TSMLoc offset) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSMutexDestroy.en.rst b/doc/developer-guide/api/functions/TSMutexDestroy.en.rst index 11de6b57b85..58cbca8e634 100644 --- a/doc/developer-guide/api/functions/TSMutexDestroy.en.rst +++ b/doc/developer-guide/api/functions/TSMutexDestroy.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void TSMutexDestroy(TSMutex mutexp) +.. function:: void TSMutexDestroy(TSMutex mutexp) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSMutexLock.en.rst b/doc/developer-guide/api/functions/TSMutexLock.en.rst index d7cd24af55f..6540c414dc5 100644 --- a/doc/developer-guide/api/functions/TSMutexLock.en.rst +++ b/doc/developer-guide/api/functions/TSMutexLock.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void TSMutexLock(TSMutex mutexp) +.. function:: void TSMutexLock(TSMutex mutexp) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSMutexLockTry.en.rst b/doc/developer-guide/api/functions/TSMutexLockTry.en.rst index be8754efb75..54dc63e25c5 100644 --- a/doc/developer-guide/api/functions/TSMutexLockTry.en.rst +++ b/doc/developer-guide/api/functions/TSMutexLockTry.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: TSReturnCode TSMutexLockTry(TSMutex mutexp) +.. function:: TSReturnCode TSMutexLockTry(TSMutex mutexp) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSMutexUnlock.en.rst b/doc/developer-guide/api/functions/TSMutexUnlock.en.rst index 27484f83e30..cd0d9774b0b 100644 --- a/doc/developer-guide/api/functions/TSMutexUnlock.en.rst +++ b/doc/developer-guide/api/functions/TSMutexUnlock.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void TSMutexUnlock(TSMutex mutexp) +.. function:: void TSMutexUnlock(TSMutex mutexp) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSSslServerContextCreate.en.rst b/doc/developer-guide/api/functions/TSSslServerContextCreate.en.rst index 8ded24ad066..e162cd999ff 100644 --- a/doc/developer-guide/api/functions/TSSslServerContextCreate.en.rst +++ b/doc/developer-guide/api/functions/TSSslServerContextCreate.en.rst @@ -31,7 +31,7 @@ Synopsis #include .. function:: TSSslContext TSSslServerContextCreate(TSSslX509 *cert, char *certname) -.. function:: void TSSslContextDestroy(TSSslContext ctx) +.. function:: void TSSslContextDestroy(TSSslContext ctx) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSTextLogObjectCreate.en.rst b/doc/developer-guide/api/functions/TSTextLogObjectCreate.en.rst index ceacafe2edd..d2aeaa0405f 100644 --- a/doc/developer-guide/api/functions/TSTextLogObjectCreate.en.rst +++ b/doc/developer-guide/api/functions/TSTextLogObjectCreate.en.rst @@ -33,8 +33,8 @@ Synopsis .. function:: TSReturnCode TSTextLogObjectCreate(const char * filename, int mode, TSTextLogObject * new_log_obj) .. function:: TSReturnCode TSTextLogObjectWrite(TSTextLogObject the_object, const char * format, ...) -.. function:: void TSTextLogObjectFlush(TSTextLogObject the_object) -.. function:: TSReturnCode TSTextLogObjectDestroy(TSTextLogObject the_object) +.. function:: void TSTextLogObjectFlush(TSTextLogObject the_object) noexcept +.. function:: TSReturnCode TSTextLogObjectDestroy(TSTextLogObject the_object) noexcept .. function:: void TSTextLogObjectHeaderSet(TSTextLogObject the_object, const char * header) .. function:: TSReturnCode TSTextLogObjectRollingEnabledSet(TSTextLogObject the_object, int rolling_enabled) .. function:: void TSTextLogObjectRollingIntervalSecSet(TSTextLogObject the_object, int rolling_interval_sec) diff --git a/doc/developer-guide/api/functions/TSThreadDestroy.en.rst b/doc/developer-guide/api/functions/TSThreadDestroy.en.rst index c0a9b425280..76e8680769b 100644 --- a/doc/developer-guide/api/functions/TSThreadDestroy.en.rst +++ b/doc/developer-guide/api/functions/TSThreadDestroy.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void TSThreadDestroy(TSThread thread) +.. function:: void TSThreadDestroy(TSThread thread) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSVConnAbort.en.rst b/doc/developer-guide/api/functions/TSVConnAbort.en.rst index afd9547bc85..13806184140 100644 --- a/doc/developer-guide/api/functions/TSVConnAbort.en.rst +++ b/doc/developer-guide/api/functions/TSVConnAbort.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void TSVConnAbort(TSVConn connp, int error) +.. function:: void TSVConnAbort(TSVConn connp, int error) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSVConnClose.en.rst b/doc/developer-guide/api/functions/TSVConnClose.en.rst index 0e2570ae0fc..8363328d124 100644 --- a/doc/developer-guide/api/functions/TSVConnClose.en.rst +++ b/doc/developer-guide/api/functions/TSVConnClose.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void TSVConnClose(TSVConn connp) +.. function:: void TSVConnClose(TSVConn connp) noexcept Description =========== diff --git a/doc/developer-guide/api/functions/TSVConnShutdown.en.rst b/doc/developer-guide/api/functions/TSVConnShutdown.en.rst index 1eda060da6f..5370ab6be20 100644 --- a/doc/developer-guide/api/functions/TSVConnShutdown.en.rst +++ b/doc/developer-guide/api/functions/TSVConnShutdown.en.rst @@ -28,7 +28,7 @@ Synopsis #include -.. function:: void TSVConnShutdown(TSVConn connp, int read, int write) +.. function:: void TSVConnShutdown(TSVConn connp, int read, int write) noexcept Description =========== diff --git a/doc/developer-guide/plugins/getting-started/index.en.rst b/doc/developer-guide/plugins/getting-started/index.en.rst index aaf577ba60e..35008e84088 100644 --- a/doc/developer-guide/plugins/getting-started/index.en.rst +++ b/doc/developer-guide/plugins/getting-started/index.en.rst @@ -33,7 +33,17 @@ Getting Started The Traffic Server API enables you to create plugins, using the C++ programming language, that customize the behavior of your Traffic Server installation. (Your plugin may not work properly if you use a version of C++ -older than C++17.) This chapter contains the following sections: +older than C++17.) + +C++ exceptions are not a supported error channel across the plugin API. API +functions report failure through their return values, and a plugin must not +allow one of its own exceptions to propagate into Traffic Server (for example +out of a continuation handler). API functions that plugins commonly call +during cleanup are declared ``noexcept``; if an internal error would otherwise +escape such a call as an exception, Traffic Server aborts with a message +naming the function rather than raising an exception in the plugin. + +This chapter contains the following sections: - `Understanding Traffic Server Plugins`_ -- a brief introduction to plugins. diff --git a/include/ts/ts.h b/include/ts/ts.h index 5a3de2e585d..a1ea54544f9 100644 --- a/include/ts/ts.h +++ b/include/ts/ts.h @@ -85,7 +85,7 @@ TSstrndup(const char *p, int64_t n) @param mloc location of the handle to be released. */ -TSReturnCode TSHandleMLocRelease(TSMBuffer bufp, TSMLoc parent, TSMLoc mloc); +TSReturnCode TSHandleMLocRelease(TSMBuffer bufp, TSMLoc parent, TSMLoc mloc) noexcept; /* -------------------------------------------------------------------------- Install and plugin locations */ @@ -297,13 +297,13 @@ char *TSfgets(TSFile filep, char *buf, size_t length); immediate attention. */ -void TSStatus(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log information -void TSNote(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log significant information -void TSWarning(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log concerning information -void TSError(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log operational failure, fail CI -void TSFatal(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log recoverable crash, fail CI, exit & restart -void TSAlert(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log recoverable crash, fail CI, exit & restart, Ops attention -void TSEmergency(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log unrecoverable crash, fail CI, exit, Ops attention +void TSStatus(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log information +void TSNote(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log significant information +void TSWarning(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log concerning information +void TSError(const char *fmt, ...) noexcept TS_PRINTFLIKE(1, 2); // Log operational failure, fail CI +void TSFatal(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log recoverable crash, fail CI, exit & restart +void TSAlert(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log recoverable crash, fail CI, exit & restart, Ops attention +void TSEmergency(const char *fmt, ...) TS_PRINTFLIKE(1, 2); // Log unrecoverable crash, fail CI, exit, Ops attention /* -------------------------------------------------------------------------- Assertions */ @@ -331,7 +331,7 @@ TSMBuffer TSMBufferCreate(void); @param bufp marshal buffer to be destroyed. */ -TSReturnCode TSMBufferDestroy(TSMBuffer bufp); +TSReturnCode TSMBufferDestroy(TSMBuffer bufp) noexcept; /* -------------------------------------------------------------------------- URLs */ @@ -817,7 +817,7 @@ TSReturnCode TSMimeHdrCreate(TSMBuffer bufp, TSMLoc *locp); @param offset location of the MIME header. */ -TSReturnCode TSMimeHdrDestroy(TSMBuffer bufp, TSMLoc offset); +TSReturnCode TSMimeHdrDestroy(TSMBuffer bufp, TSMLoc offset) noexcept; /** Copies a specified MIME header to a specified marshal buffer, @@ -1059,7 +1059,7 @@ TSReturnCode TSMimeFormatDate(time_t const value_time, char *const value_str, in HTTP headers */ TSHttpParser TSHttpParserCreate(void); void TSHttpParserClear(TSHttpParser parser); -void TSHttpParserDestroy(TSHttpParser parser); +void TSHttpParserDestroy(TSHttpParser parser) noexcept; /** Parses an HTTP request header. The HTTP header must have already @@ -1102,7 +1102,7 @@ TSMLoc TSHttpHdrCreate(TSMBuffer bufp); call to TSHandleMLocRelease(). */ -void TSHttpHdrDestroy(TSMBuffer bufp, TSMLoc offset); +void TSHttpHdrDestroy(TSMBuffer bufp, TSMLoc offset) noexcept; TSReturnCode TSHttpHdrClone(TSMBuffer dest_bufp, TSMBuffer src_bufp, TSMLoc src_hdr, TSMLoc *locp); @@ -1154,19 +1154,19 @@ const char *TSHttpHdrReasonLookup(TSHttpStatus status); Threads */ TSThread TSThreadCreate(TSThreadFunc func, void *data); TSThread TSThreadInit(void); -void TSThreadDestroy(TSThread thread); -void TSThreadWait(TSThread thread); +void TSThreadDestroy(TSThread thread) noexcept; +void TSThreadWait(TSThread thread) noexcept; TSThread TSThreadSelf(void); TSEventThread TSEventThreadSelf(void); /* -------------------------------------------------------------------------- Mutexes */ TSMutex TSMutexCreate(void); -void TSMutexDestroy(TSMutex mutexp); -void TSMutexLock(TSMutex mutexp); -TSReturnCode TSMutexLockTry(TSMutex mutexp); +void TSMutexDestroy(TSMutex mutexp) noexcept; +void TSMutexLock(TSMutex mutexp) noexcept; +TSReturnCode TSMutexLockTry(TSMutex mutexp) noexcept; -void TSMutexUnlock(TSMutex mutexp); +void TSMutexUnlock(TSMutex mutexp) noexcept; /** Scoped lock guard for a @c TSMutex. @@ -1231,7 +1231,7 @@ TSReturnCode TSCacheKeyPinnedSet(TSCacheKey key, time_t pin_in_cache); @param key to be destroyed. */ -TSReturnCode TSCacheKeyDestroy(TSCacheKey key); +TSReturnCode TSCacheKeyDestroy(TSCacheKey key) noexcept; /* -------------------------------------------------------------------------- cache url */ @@ -1266,9 +1266,9 @@ TSHRTime TShrtime(void); /* -------------------------------------------------------------------------- Continuations */ TSCont TSContCreate(TSEventFunc funcp, TSMutex mutexp); -void TSContDestroy(TSCont contp); -void TSContDataSet(TSCont contp, void *data); -void *TSContDataGet(TSCont contp); +void TSContDestroy(TSCont contp) noexcept; +void TSContDataSet(TSCont contp, void *data) noexcept; +void *TSContDataGet(TSCont contp) noexcept; TSAction TSContScheduleOnPool(TSCont contp, TSHRTime timeout, TSThreadPool tp); TSAction TSContScheduleOnThread(TSCont contp, TSHRTime timeout, TSEventThread ethread); std::vector TSContScheduleOnEntirePool(TSCont contp, TSHRTime timeout, TSThreadPool tp); @@ -1338,7 +1338,7 @@ TSReturnCode TSSslSecretUpdate(const char *secret_name, int secret_name_length); /* Create a new SSL context based on the settings in records.yaml */ TSSslContext TSSslServerContextCreate(TSSslX509 cert, const char *certname, const char *rsp_file); -void TSSslContextDestroy(TSSslContext ctx); +void TSSslContextDestroy(TSSslContext ctx) noexcept; TSReturnCode TSSslTicketKeyUpdate(char *ticketData, int ticketDataLen); TSAcceptor TSAcceptorGet(TSVConn sslp); TSAcceptor TSAcceptorGetbyID(int ID); @@ -2055,7 +2055,7 @@ void TSFetchLaunch(TSFetchSM fetch_sm); * * @param fetch_sm: returned value of TSFetchCreate(). */ -void TSFetchDestroy(TSFetchSM fetch_sm); +void TSFetchDestroy(TSFetchSM fetch_sm) noexcept; /* * Set user-defined data in FetchSM @@ -2090,7 +2090,7 @@ void TSHttpAltInfoQualitySet(TSHttpAltInfo infop, float quality); /* -------------------------------------------------------------------------- Actions */ -void TSActionCancel(TSAction actionp); +void TSActionCancel(TSAction actionp) noexcept; int TSActionDone(TSAction actionp); /* -------------------------------------------------------------------------- @@ -2101,9 +2101,9 @@ int TSVConnClosedGet(TSVConn connp); TSVIO TSVConnRead(TSVConn connp, TSCont contp, TSIOBuffer bufp, int64_t nbytes); TSVIO TSVConnWrite(TSVConn connp, TSCont contp, TSIOBufferReader readerp, int64_t nbytes); -void TSVConnClose(TSVConn connp); -void TSVConnAbort(TSVConn connp, int error); -void TSVConnShutdown(TSVConn connp, int read, int write); +void TSVConnClose(TSVConn connp) noexcept; +void TSVConnAbort(TSVConn connp, int error) noexcept; +void TSVConnShutdown(TSVConn connp, int read, int write) noexcept; /* -------------------------------------------------------------------------- Cache VConnections */ @@ -2397,7 +2397,7 @@ int64_t TSIOBufferWaterMarkGet(TSIOBuffer bufp); */ void TSIOBufferWaterMarkSet(TSIOBuffer bufp, int64_t water_mark); -void TSIOBufferDestroy(TSIOBuffer bufp); +void TSIOBufferDestroy(TSIOBuffer bufp) noexcept; TSIOBufferBlock TSIOBufferStart(TSIOBuffer bufp); int64_t TSIOBufferCopy(TSIOBuffer bufp, TSIOBufferReader readerp, int64_t length, int64_t offset); @@ -2424,10 +2424,10 @@ int64_t TSIOBufferBlockWriteAvail(TSIOBufferBlock blockp); TSIOBufferReader TSIOBufferReaderAlloc(TSIOBuffer bufp); TSIOBufferReader TSIOBufferReaderClone(TSIOBufferReader readerp); -void TSIOBufferReaderFree(TSIOBufferReader readerp); +void TSIOBufferReaderFree(TSIOBufferReader readerp) noexcept; TSIOBufferBlock TSIOBufferReaderStart(TSIOBufferReader readerp); -void TSIOBufferReaderConsume(TSIOBufferReader readerp, int64_t nbytes); -int64_t TSIOBufferReaderAvail(TSIOBufferReader readerp); +void TSIOBufferReaderConsume(TSIOBufferReader readerp, int64_t nbytes) noexcept; +int64_t TSIOBufferReaderAvail(TSIOBufferReader readerp) noexcept; int64_t TSIOBufferReaderCopy(TSIOBufferReader readerp, void *buf, int64_t length); struct sockaddr const *TSNetVConnLocalAddrGet(TSVConn vc); @@ -2607,7 +2607,7 @@ TSReturnCode TSTextLogObjectWrite(TSTextLogObject the_object, const char *format flushed. */ -void TSTextLogObjectFlush(TSTextLogObject the_object); +void TSTextLogObjectFlush(TSTextLogObject the_object) noexcept; /** Destroys a log object and releases the memory allocated to it. @@ -2616,7 +2616,7 @@ void TSTextLogObjectFlush(TSTextLogObject the_object); @param the_object custom log to be destroyed. */ -TSReturnCode TSTextLogObjectDestroy(TSTextLogObject the_object); +TSReturnCode TSTextLogObjectDestroy(TSTextLogObject the_object) noexcept; /** Set log header. diff --git a/include/tscpp/api/Logger.h b/include/tscpp/api/Logger.h index 049262422cc..a7cf7608cc8 100644 --- a/include/tscpp/api/Logger.h +++ b/include/tscpp/api/Logger.h @@ -88,7 +88,7 @@ * * @private */ -void TSError(const char *fmt, ...) ATSCPPAPI_PRINTFLIKE(1, 2); +void TSError(const char *fmt, ...) noexcept ATSCPPAPI_PRINTFLIKE(1, 2); // This is weird, but see the following: // http://stackoverflow.com/questions/5641427/how-to-make-preprocessor-generate-a-string-for-line-keyword diff --git a/include/tsutil/Assert.h b/include/tsutil/Assert.h index a536e426401..2903c754b53 100644 --- a/include/tsutil/Assert.h +++ b/include/tsutil/Assert.h @@ -28,7 +28,7 @@ namespace ts { -void do_abort(const SourceLocation &loc, const char *expr, const char *message = nullptr); +[[noreturn]] void do_abort(const SourceLocation &loc, const char *expr, const char *message = nullptr) noexcept; } diff --git a/include/tsutil/TsSharedMutex.h b/include/tsutil/TsSharedMutex.h index bf098850401..76903c68254 100644 --- a/include/tsutil/TsSharedMutex.h +++ b/include/tsutil/TsSharedMutex.h @@ -24,6 +24,8 @@ #pragma once +#include +#include #include #include "tsutil/Strerror.h" #include "tsutil/Assert.h" @@ -172,10 +174,15 @@ class TS_CAPABILITY("shared_mutex") shared_mutex pthread_rwlock_t _lock = PTHREAD_RWLOCK_INITIALIZER; #endif - static void - _call_fatal(char const *func_name, void *ptr, int errnum) - { + [[noreturn]] static void + _call_fatal(char const *func_name, void *ptr, int errnum) noexcept + try { fatal_error("{}({}) failed: {} ({})", func_name, ptr, Strerror(errnum).c_str(), errnum); + } catch (...) { + // Formatting the message can throw (it allocates); abort with a minimal + // breadcrumb rather than let an exception escape into a noexcept destructor. + fprintf(stderr, "shared_mutex: %s failed (%d); abort message formatting threw\n", func_name, errnum); + std::abort(); } // In debug builds, make sure shared vs. exclusive locks and unlocks are properly paired. diff --git a/plugins/esi/test/print_funcs.cc b/plugins/esi/test/print_funcs.cc index d73b973d654..5cff08abf0c 100644 --- a/plugins/esi/test/print_funcs.cc +++ b/plugins/esi/test/print_funcs.cc @@ -102,7 +102,7 @@ DbgCtl::_override_global_on() } void -TSError(const char *fmt, ...) +TSError(const char *fmt, ...) noexcept { char buf[LINE_SIZE]; va_list ap; diff --git a/plugins/experimental/sslheaders/unit_tests/test_sslheaders.cc b/plugins/experimental/sslheaders/unit_tests/test_sslheaders.cc index 5d967688d6b..f6400a5bf51 100644 --- a/plugins/experimental/sslheaders/unit_tests/test_sslheaders.cc +++ b/plugins/experimental/sslheaders/unit_tests/test_sslheaders.cc @@ -41,7 +41,7 @@ DbgCtl::print(const char *tag, char const * /* file */, char const * /* function } void -TSError(const char *fmt, ...) +TSError(const char *fmt, ...) noexcept { va_list args; diff --git a/plugins/header_rewrite/header_rewrite_test.cc b/plugins/header_rewrite/header_rewrite_test.cc index cb166fd7040..7ec83230a36 100644 --- a/plugins/header_rewrite/header_rewrite_test.cc +++ b/plugins/header_rewrite/header_rewrite_test.cc @@ -43,7 +43,7 @@ const char PLUGIN_NAME_DBG[] = "TEST_dbg_header_rewrite"; } // namespace header_rewrite_ns void -TSError(const char *fmt, ...) +TSError(const char *fmt, ...) noexcept { va_list args; diff --git a/plugins/header_rewrite/matcher_tests.cc b/plugins/header_rewrite/matcher_tests.cc index 83c8c1bc6ad..f943aca814a 100644 --- a/plugins/header_rewrite/matcher_tests.cc +++ b/plugins/header_rewrite/matcher_tests.cc @@ -31,7 +31,7 @@ _TSAssert(const char *, const char *, int) } void -TSError(const char *fmt, ...) +TSError(const char *fmt, ...) noexcept { va_list args; @@ -48,7 +48,7 @@ TSHttpHdrStatusGet(TSMBuffer, TSMLoc) } TSReturnCode -TSHandleMLocRelease(TSMBuffer, TSMLoc, TSMLoc) +TSHandleMLocRelease(TSMBuffer, TSMLoc, TSMLoc) noexcept { return TS_SUCCESS; } diff --git a/plugins/multiplexer/unit_tests/test_chunk_decoder.cc b/plugins/multiplexer/unit_tests/test_chunk_decoder.cc index 04ff18b81f5..a342efa5b06 100644 --- a/plugins/multiplexer/unit_tests/test_chunk_decoder.cc +++ b/plugins/multiplexer/unit_tests/test_chunk_decoder.cc @@ -74,14 +74,14 @@ TSIOBufferReaderStart(TSIOBufferReader /* readerp ATS_UNUSED */) } void -TSIOBufferReaderConsume(TSIOBufferReader /* readerp ATS_UNUSED */, int64_t nbytes) +TSIOBufferReaderConsume(TSIOBufferReader /* readerp ATS_UNUSED */, int64_t nbytes) noexcept { consumed += nbytes; reader_avail -= nbytes; } int64_t -TSIOBufferReaderAvail(TSIOBufferReader /* readerp ATS_UNUSED */) +TSIOBufferReaderAvail(TSIOBufferReader /* readerp ATS_UNUSED */) noexcept { return reader_avail; } diff --git a/src/api/InkAPI.cc b/src/api/InkAPI.cc index 59a94991c7e..7fe054968bb 100644 --- a/src/api/InkAPI.cc +++ b/src/api/InkAPI.cc @@ -33,6 +33,7 @@ #include "iocore/net/NetHandler.h" #include "iocore/net/UDPNet.h" #include "tscore/ink_config.h" +#include "tscore/ink_error.h" #include "tscore/ink_platform.h" #include "tscore/ink_base64.h" #include "tscore/Encoding.h" @@ -248,13 +249,15 @@ TSWarning(const char *fmt, ...) } void -TSError(const char *fmt, ...) -{ +TSError(const char *fmt, ...) noexcept +try { va_list args; va_start(args, fmt); ErrorV(fmt, args); va_end(args); +} catch (...) { + ink_abort("exception escaped %s", __func__); } void @@ -833,8 +836,8 @@ TSfgets(TSFile filep, char *buf, size_t length) //////////////////////////////////////////////////////////////////// TSReturnCode -TSHandleMLocRelease(TSMBuffer bufp, TSMLoc parent, TSMLoc mloc) -{ +TSHandleMLocRelease(TSMBuffer bufp, TSMLoc parent, TSMLoc mloc) noexcept +try { MIMEFieldSDKHandle *field_handle; HdrHeapObjImpl *obj = reinterpret_cast(mloc); @@ -863,6 +866,8 @@ TSHandleMLocRelease(TSMBuffer bufp, TSMLoc parent, TSMLoc mloc) ink_release_assert(!"invalid mloc"); return TS_ERROR; } +} catch (...) { + ink_abort("exception escaped %s", __func__); } //////////////////////////////////////////////////////////////////// @@ -887,8 +892,8 @@ TSMBufferCreate() } TSReturnCode -TSMBufferDestroy(TSMBuffer bufp) -{ +TSMBufferDestroy(TSMBuffer bufp) noexcept +try { // Allow to modify the buffer only // if bufp is modifiable. If bufp is not modifiable return // TS_ERROR. If allowed, return TS_SUCCESS. Changed the @@ -902,6 +907,8 @@ TSMBufferDestroy(TSMBuffer bufp) sdk_heap->m_heap->destroy(); delete sdk_heap; return TS_SUCCESS; +} catch (...) { + ink_abort("exception escaped %s", __func__); } //////////////////////////////////////////////////////////////////// @@ -1469,8 +1476,8 @@ TSMimeHdrCreate(TSMBuffer bufp, TSMLoc *locp) } TSReturnCode -TSMimeHdrDestroy(TSMBuffer bufp, TSMLoc obj) -{ +TSMimeHdrDestroy(TSMBuffer bufp, TSMLoc obj) noexcept +try { // Allow to modify the buffer only // if bufp is modifiable. If bufp is not modifiable return // TS_ERROR. If allowed, return TS_SUCCESS. Changed the @@ -1486,6 +1493,8 @@ TSMimeHdrDestroy(TSMBuffer bufp, TSMLoc obj) mime_hdr_destroy((reinterpret_cast(bufp))->m_heap, mh); return TS_SUCCESS; +} catch (...) { + ink_abort("exception escaped %s", __func__); } TSReturnCode @@ -2548,11 +2557,13 @@ TSHttpParserClear(TSHttpParser parser) } void -TSHttpParserDestroy(TSHttpParser parser) -{ +TSHttpParserDestroy(TSHttpParser parser) noexcept +try { sdk_assert(sdk_sanity_check_http_parser(parser) == TS_SUCCESS); http_parser_clear(reinterpret_cast(parser)); ats_free(parser); +} catch (...) { + ink_abort("exception escaped %s", __func__); } /***********/ @@ -2571,8 +2582,8 @@ TSHttpHdrCreate(TSMBuffer bufp) } void -TSHttpHdrDestroy(TSMBuffer bufp, TSMLoc obj) -{ +TSHttpHdrDestroy(TSMBuffer bufp, TSMLoc obj) noexcept +try { sdk_assert(sdk_sanity_check_mbuffer(bufp) == TS_SUCCESS); sdk_assert(sdk_sanity_check_http_hdr_handle(obj) == TS_SUCCESS); @@ -2580,6 +2591,8 @@ TSHttpHdrDestroy(TSMBuffer bufp, TSMLoc obj) // so do nothing! // HDR FIX ME - Did this free the MBuffer in Pete's old system +} catch (...) { + ink_abort("exception escaped %s", __func__); } TSReturnCode @@ -3140,8 +3153,8 @@ TSCacheKeyPinnedSet(TSCacheKey key, time_t pin_in_cache) } TSReturnCode -TSCacheKeyDestroy(TSCacheKey key) -{ +TSCacheKeyDestroy(TSCacheKey key) noexcept +try { sdk_assert(sdk_sanity_check_cachekey(key) == TS_SUCCESS); if ((reinterpret_cast(key))->magic != CACHE_INFO_MAGIC_ALIVE) { @@ -3154,6 +3167,8 @@ TSCacheKeyDestroy(TSCacheKey key) i->magic = CACHE_INFO_MAGIC_DEAD; delete i; return TS_SUCCESS; +} catch (...) { + ink_abort("exception escaped %s", __func__); } TSCacheHttpInfo @@ -3415,8 +3430,8 @@ TSContCreate(TSEventFunc funcp, TSMutex mutexp) } void -TSContDestroy(TSCont contp) -{ +TSContDestroy(TSCont contp) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS); INKContInternal *i = reinterpret_cast(contp); @@ -3426,26 +3441,32 @@ TSContDestroy(TSCont contp) } i->destroy(); +} catch (...) { + ink_abort("exception escaped %s", __func__); } void -TSContDataSet(TSCont contp, void *data) -{ +TSContDataSet(TSCont contp, void *data) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS); INKContInternal *i = reinterpret_cast(contp); i->mdata = data; +} catch (...) { + ink_abort("exception escaped %s", __func__); } void * -TSContDataGet(TSCont contp) -{ +TSContDataGet(TSCont contp) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(contp) == TS_SUCCESS); INKContInternal *i = reinterpret_cast(contp); return i->mdata; +} catch (...) { + ink_abort("exception escaped %s", __func__); } TSAction @@ -5843,8 +5864,8 @@ TSHttpConnectTransparent(sockaddr const *client_addr, sockaddr const *server_add /* Actions */ void -TSActionCancel(TSAction actionp) -{ +TSActionCancel(TSAction actionp) noexcept +try { Action *thisaction; INKContInternal *i; @@ -5867,6 +5888,8 @@ TSActionCancel(TSAction actionp) } thisaction->cancel(); +} catch (...) { + ink_abort("exception escaped %s", __func__); } // Currently no error handling necessary, actionp can be anything. @@ -6024,26 +6047,30 @@ TSVConnWrite(TSVConn connp, TSCont contp, TSIOBufferReader readerp, int64_t nbyt } void -TSVConnClose(TSVConn connp) -{ +TSVConnClose(TSVConn connp) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); VConnection *vc = reinterpret_cast(connp); vc->do_io_close(); +} catch (...) { + ink_abort("exception escaped %s", __func__); } void -TSVConnAbort(TSVConn connp, int error) -{ +TSVConnAbort(TSVConn connp, int error) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); VConnection *vc = reinterpret_cast(connp); vc->do_io_close(error); +} catch (...) { + ink_abort("exception escaped %s", __func__); } void -TSVConnShutdown(TSVConn connp, int read, int write) -{ +TSVConnShutdown(TSVConn connp, int read, int write) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(connp) == TS_SUCCESS); VConnection *vc = reinterpret_cast(connp); @@ -6055,6 +6082,8 @@ TSVConnShutdown(TSVConn connp, int read, int write) } else if (write) { vc->do_io_shutdown(IO_SHUTDOWN_WRITE); } +} catch (...) { + ink_abort("exception escaped %s", __func__); } int64_t @@ -6564,16 +6593,18 @@ TSTextLogObjectWrite(TSTextLogObject the_object, const char *format, ...) } void -TSTextLogObjectFlush(TSTextLogObject the_object) -{ +TSTextLogObjectFlush(TSTextLogObject the_object) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(the_object) == TS_SUCCESS); (reinterpret_cast(the_object))->force_new_buffer(); +} catch (...) { + ink_abort("exception escaped %s", __func__); } TSReturnCode -TSTextLogObjectDestroy(TSTextLogObject the_object) -{ +TSTextLogObjectDestroy(TSTextLogObject the_object) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(the_object) == TS_SUCCESS); if (Log::config->log_object_manager.unmanage_api_object(reinterpret_cast(the_object))) { @@ -6581,6 +6612,8 @@ TSTextLogObjectDestroy(TSTextLogObject the_object) } return TS_ERROR; +} catch (...) { + ink_abort("exception escaped %s", __func__); } void @@ -6892,11 +6925,13 @@ TSFetchLaunch(TSFetchSM fetch_sm) } void -TSFetchDestroy(TSFetchSM fetch_sm) -{ +TSFetchDestroy(TSFetchSM fetch_sm) noexcept +try { sdk_assert(sdk_sanity_check_fetch_sm(fetch_sm) == TS_SUCCESS); (reinterpret_cast(fetch_sm))->ext_destroy(); +} catch (...) { + ink_abort("exception escaped %s", __func__); } void @@ -8251,9 +8286,11 @@ TSSslServerContextCreate(TSSslX509 cert, const char *certname, const char *rsp_f } void -TSSslContextDestroy(TSSslContext ctx) -{ +TSSslContextDestroy(TSSslContext ctx) noexcept +try { SSLReleaseContext(reinterpret_cast(ctx)); +} catch (...) { + ink_abort("exception escaped %s", __func__); } TSReturnCode diff --git a/src/api/InkIOCoreAPI.cc b/src/api/InkIOCoreAPI.cc index f5f6455fbe4..b1a06a5dcfe 100644 --- a/src/api/InkIOCoreAPI.cc +++ b/src/api/InkIOCoreAPI.cc @@ -28,6 +28,7 @@ */ #include "tscore/ink_platform.h" +#include "tscore/ink_error.h" #include "ts/ts.h" #include "ts/InkAPIPrivateIOCore.h" #include "../iocore/net/P_UnixUDPConnection.h" @@ -160,8 +161,8 @@ TSThreadCreate(TSThreadFunc func, void *data) // needs to delete the thread, it must first wait for the thread to // complete. void -TSThreadWait(TSThread thread) -{ +TSThreadWait(TSThread thread) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(thread) == TS_SUCCESS); INKThreadInternal *ithread = reinterpret_cast(thread); @@ -172,6 +173,8 @@ TSThreadWait(TSThread thread) } ink_mutex_release(&ithread->completion.lock); +} catch (...) { + ink_abort("exception escaped %s", __func__); } TSThread @@ -193,8 +196,8 @@ TSThreadInit() } void -TSThreadDestroy(TSThread thread) -{ +TSThreadDestroy(TSThread thread) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(thread) == TS_SUCCESS); INKThreadInternal *ithread = reinterpret_cast(thread); @@ -210,6 +213,8 @@ TSThreadDestroy(TSThread thread) } delete ithread; +} catch (...) { + ink_abort("exception escaped %s", __func__); } TSThread @@ -246,8 +251,8 @@ TSMutexCreate() } void -TSMutexDestroy(TSMutex m) -{ +TSMutexDestroy(TSMutex m) noexcept +try { sdk_assert(sdk_sanity_check_mutex(m) == TS_SUCCESS); ProxyMutex *mutexp = reinterpret_cast(m); @@ -255,6 +260,8 @@ TSMutexDestroy(TSMutex m) ink_release_assert(mutexp->refcount() == 0); mutexp->free(); } +} catch (...) { + ink_abort("exception escaped %s", __func__); } /* The following two APIs are for Into work, actually, APIs of Mutex @@ -288,27 +295,33 @@ TSMutexCheck(TSMutex mutex) } void -TSMutexLock(TSMutex mutexp) -{ +TSMutexLock(TSMutex mutexp) noexcept +try { sdk_assert(sdk_sanity_check_mutex(mutexp) == TS_SUCCESS); ProxyMutex *proxy_mutex = reinterpret_cast(mutexp); MUTEX_TAKE_LOCK(proxy_mutex, this_ethread()); +} catch (...) { + ink_abort("exception escaped %s", __func__); } TSReturnCode -TSMutexLockTry(TSMutex mutexp) -{ +TSMutexLockTry(TSMutex mutexp) noexcept +try { sdk_assert(sdk_sanity_check_mutex(mutexp) == TS_SUCCESS); ProxyMutex *proxy_mutex = reinterpret_cast(mutexp); return (MUTEX_TAKE_TRY_LOCK(proxy_mutex, this_ethread()) ? TS_SUCCESS : TS_ERROR); +} catch (...) { + ink_abort("exception escaped %s", __func__); } void -TSMutexUnlock(TSMutex mutexp) -{ +TSMutexUnlock(TSMutex mutexp) noexcept +try { sdk_assert(sdk_sanity_check_mutex(mutexp) == TS_SUCCESS); ProxyMutex *proxy_mutex(reinterpret_cast(mutexp)); MUTEX_UNTAKE_LOCK(proxy_mutex, this_ethread()); +} catch (...) { + ink_abort("exception escaped %s", __func__); } /* VIOs */ @@ -447,10 +460,12 @@ TSIOBufferSizedCreate(TSIOBufferSizeIndex index) } void -TSIOBufferDestroy(TSIOBuffer bufp) -{ +TSIOBufferDestroy(TSIOBuffer bufp) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(bufp) == TS_SUCCESS); free_MIOBuffer((MIOBuffer *)bufp); +} catch (...) { + ink_abort("exception escaped %s", __func__); } TSIOBufferBlock @@ -657,12 +672,14 @@ TSIOBufferReaderClone(TSIOBufferReader readerp) } void -TSIOBufferReaderFree(TSIOBufferReader readerp) -{ +TSIOBufferReaderFree(TSIOBufferReader readerp) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(readerp) == TS_SUCCESS); IOBufferReader *r = (IOBufferReader *)readerp; r->mbuf->dealloc_reader(r); +} catch (...) { + ink_abort("exception escaped %s", __func__); } TSIOBufferBlock @@ -680,20 +697,24 @@ TSIOBufferReaderStart(TSIOBufferReader readerp) } void -TSIOBufferReaderConsume(TSIOBufferReader readerp, int64_t nbytes) -{ +TSIOBufferReaderConsume(TSIOBufferReader readerp, int64_t nbytes) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(readerp) == TS_SUCCESS); sdk_assert(nbytes >= 0); IOBufferReader *r = (IOBufferReader *)readerp; r->consume(nbytes); +} catch (...) { + ink_abort("exception escaped %s", __func__); } int64_t -TSIOBufferReaderAvail(TSIOBufferReader readerp) -{ +TSIOBufferReaderAvail(TSIOBufferReader readerp) noexcept +try { sdk_assert(sdk_sanity_check_iocore_structure(readerp) == TS_SUCCESS); IOBufferReader *r = (IOBufferReader *)readerp; return r->read_avail(); +} catch (...) { + ink_abort("exception escaped %s", __func__); } diff --git a/src/cripts/unit_tests/stub.cc b/src/cripts/unit_tests/stub.cc index 65680db4a19..9214b514b19 100644 --- a/src/cripts/unit_tests/stub.cc +++ b/src/cripts/unit_tests/stub.cc @@ -28,7 +28,7 @@ TSWarning(const char * /* fmt */, ...) } void -TSError(const char * /* fmt */, ...) +TSError(const char * /* fmt */, ...) noexcept { } @@ -39,12 +39,12 @@ TSContCreate(TSEventFunc, TSMutex) } void -TSContDataSet(TSCont, void *) +TSContDataSet(TSCont, void *) noexcept { } void * -TSContDataGet(TSCont) +TSContDataGet(TSCont) noexcept { return nullptr; } @@ -62,12 +62,12 @@ TSContScheduleEveryOnPool(TSCont, TSHRTime, TSThreadPool) } void -TSActionCancel(TSAction) +TSActionCancel(TSAction) noexcept { } void -TSContDestroy(TSCont) +TSContDestroy(TSCont) noexcept { } diff --git a/src/iocore/cache/unit_tests/stub.cc b/src/iocore/cache/unit_tests/stub.cc index 177f20be1ee..50c8239b052 100644 --- a/src/iocore/cache/unit_tests/stub.cc +++ b/src/iocore/cache/unit_tests/stub.cc @@ -51,7 +51,7 @@ TSIOBufferBlockReadStart(TSIOBufferBlock /* blockp ATS_UNUSED */, TSIOBufferRead } void -TSIOBufferReaderConsume(TSIOBufferReader /* readerp ATS_UNUSED */, int64_t /* nbytes ATS_UNUSED */) +TSIOBufferReaderConsume(TSIOBufferReader /* readerp ATS_UNUSED */, int64_t /* nbytes ATS_UNUSED */) noexcept { } diff --git a/src/tsutil/Assert.cc b/src/tsutil/Assert.cc index e94e29956d4..20e45b44f87 100644 --- a/src/tsutil/Assert.cc +++ b/src/tsutil/Assert.cc @@ -28,8 +28,8 @@ #include void -ts::do_abort(const SourceLocation &loc, const char *expr, const char *message) -{ +ts::do_abort(const SourceLocation &loc, const char *expr, const char *message) noexcept +try { swoc::LocalBufferWriter<1024> w; w.print("Fatal: <{}> {}", loc, expr); @@ -40,5 +40,10 @@ ts::do_abort(const SourceLocation &loc, const char *expr, const char *message) fprintf(stderr, "%s\n", w.data()); syslog(LOG_CRIT, "%s", w.data()); + abort(); +} catch (...) { + // Formatting the message must not stop the abort, and an exception must not + // escape into callers' noexcept contexts (e.g. destructors). + fprintf(stderr, "Fatal: <%s> (abort message formatting threw)\n", expr); abort(); }