|
48 | 48 | #include <ts/remap.h> |
49 | 49 | #include <ts/remap_version.h> |
50 | 50 | #include <tsutil/TsSharedMutex.h> |
| 51 | +#include <utility> |
51 | 52 | #include "ts/apidefs.h" |
52 | 53 | #include "tscore/ink_config.h" |
53 | 54 | #include "swoc/TextView.h" |
@@ -224,6 +225,16 @@ class S3Config |
224 | 225 | } |
225 | 226 | } |
226 | 227 |
|
| 228 | + // This handles the hoops needed to safely delete the special |
| 229 | + // plugin level instance of this class. |
| 230 | + static void deletePluginInstance(S3Config *p); |
| 231 | + |
| 232 | + TSCont |
| 233 | + releaseReloadCont() |
| 234 | + { |
| 235 | + return std::exchange(_conf_rld, nullptr); |
| 236 | + } |
| 237 | + |
227 | 238 | // Is this configuration usable? |
228 | 239 | bool |
229 | 240 | valid() const |
@@ -647,6 +658,29 @@ S3Config::parse_config(const std::string &config_fname) |
647 | 658 | return true; |
648 | 659 | } |
649 | 660 |
|
| 661 | +void |
| 662 | +S3Config::deletePluginInstance(S3Config *s3) |
| 663 | +{ |
| 664 | + // Due to a race conditions with the background continuation |
| 665 | + // the plugin shutdown has to take care not to run |
| 666 | + // when the reload continuation does. |
| 667 | + // |
| 668 | + // The order of oprations here is important, be careful making changes |
| 669 | + if (s3) { |
| 670 | + TSMutex s3_mutex_ptr = s3->config_reloader_mutex(); |
| 671 | + |
| 672 | + TSMutexLock(s3_mutex_ptr); |
| 673 | + auto cont = s3->releaseReloadCont(); |
| 674 | + delete s3; |
| 675 | + TSMutexUnlock(s3_mutex_ptr); |
| 676 | + // Its important to only destory this continuation outside of holding |
| 677 | + // its lock, but after it has been cancelled (in the S3Config destructor) |
| 678 | + if (cont != nullptr) { |
| 679 | + TSContDestroy(cont); |
| 680 | + } |
| 681 | + } |
| 682 | +} |
| 683 | + |
650 | 684 | /////////////////////////////////////////////////////////////////////////////// |
651 | 685 | // Implementation for the ConfigCache, it has to go here since we have a sort |
652 | 686 | // of circular dependency. Note that we always parse / get the configuration |
@@ -1269,11 +1303,7 @@ TSRemapNewInstance(int argc, char *argv[], void **ih, char * /* errbuf ATS_UNUSE |
1269 | 1303 | void |
1270 | 1304 | TSRemapDeleteInstance(void *ih) |
1271 | 1305 | { |
1272 | | - S3Config *s3 = static_cast<S3Config *>(ih); |
1273 | | - TSMutex s3_mutex_ptr = s3->config_reloader_mutex(); |
1274 | | - TSMutexLock(s3_mutex_ptr); |
1275 | | - delete s3; |
1276 | | - TSMutexUnlock(s3_mutex_ptr); |
| 1306 | + S3Config::deletePluginInstance(static_cast<S3Config *>(ih)); |
1277 | 1307 | } |
1278 | 1308 |
|
1279 | 1309 | /////////////////////////////////////////////////////////////////////////////// |
|
0 commit comments