diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
index 587dcc8194c..3a13998fe1f 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.cpp
@@ -121,6 +121,30 @@ void WiredTigerEventHandler::releaseSectionActivityPermit() {
         _idleCondition.notify_all();
         return;
     }
+
+WiredTigerSessionEventHandler::WiredTigerSessionEventHandler(OperationContext *opCtx) :
+      _opCtx(opCtx) {
+    WT_EVENT_HANDLER* handler = static_cast<WT_EVENT_HANDLER*>(this);
+    invariant((void*)this == (void*)handler);
+
+    handler->handle_error = mdb_handle_error_with_startup_suppression;
+    handler->handle_message = mdb_handle_message;
+    handler->handle_progress = mdb_handle_progress;
+    handler->handle_close = nullptr;
+    handler->handle_general = mdb_handle_general;
+}
+
+WT_EVENT_HANDLER* WiredTigerSessionEventHandler::getWtEventHandler() {
+    WT_EVENT_HANDLER* ret = static_cast<WT_EVENT_HANDLER*>(this);
+    invariant((void*)this == (void*)ret);
+
+    return ret;
+}
+
+void WiredTigerSessionEventHandler::changeOperationContext(OperationContext *opCtx) {
+	_opCtx = opCtx;
+}
+
 }
 
 namespace {
@@ -868,6 +892,38 @@ WT_EVENT_HANDLER defaultEventHandlers() {
     handlers.handle_general = mdb_handle_general;
     return handlers;
 }
+
+/**
+ * Defines a callback function that can be passed via a WT_EVENT_HANDLER*
+ * (WT_EVENT_HANDLER::handle_general) into WT::wiredtiger_open() call.
+ *
+ * The void* WT_SESSION::app_private is leveraged to inject MDB state into the WT code layer.
+ * Long running WT::compact operations will periodically use this callback function to check whether
+ * or not to quit early and fail the WT::compact operation.
+ */
+int mdb_session_handle_general(WT_EVENT_HANDLER* handler,
+                       WT_CONNECTION* wt_conn,
+                       WT_SESSION* session,
+                       WT_EVENT_TYPE type,
+                       void* arg) {
+    WiredTigerSessionEventHandler* wtHandler = reinterpret_cast<WiredTigerSessionEventHandler*>(handler);
+
+    if (type == WT_EVENT_COMPACT_RUNNING) {
+	    wtHandler.getOperationContext().setCompactRunning();
+    } else {
+	    return (mdb_session_handle_general(handler, wt_conn, session, type, arg));
+
+    return 0;
+}
+
+WT_EVENT_HANDLER defaultSessionEventHandlers() {
+    WT_EVENT_HANDLER handlers = {};
+    handlers.handle_error = mdb_handle_error;
+    handlers.handle_message = mdb_handle_message;
+    handlers.handle_progress = mdb_handle_progress;
+    handlers.handle_general = mdb_session_handle_general;
+    return handlers;
+}
 }  // namespace
 
 WiredTigerEventHandler::WiredTigerEventHandler() {
diff --git a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h
index c9dd12a15e6..318bc4a4df7 100644
--- a/src/mongo/db/storage/wiredtiger/wiredtiger_util.h
+++ b/src/mongo/db/storage/wiredtiger/wiredtiger_util.h
@@ -213,6 +213,25 @@ private:
     int32_t _activeSections{0};
 };
 
+/**
+ * Returns a WT_EVENT_HANDLER with default handlers for a WiredTiger session, which has a one
+ * to one mapping to a MongoDB operation context.
+ */
+class WiredTigerSessionEventHandler : private WT_EVENT_HANDLER {
+public:
+    WiredTigerSessionEventHandler(OperationContext *opCtx);
+
+    WT_EVENT_HANDLER* getWtEventHandler();
+
+    /**
+     * When a session is retrieved from the cache and associated with a new operation
+     * context object, the event handler needs to be updated to point to the same object.
+     */
+    void changeOperationContext(OperationContext *opCtx);
+private:
+    OperationContext *_opCtx = NULL;
+};
+
 class WiredTigerUtil {
     WiredTigerUtil(const WiredTigerUtil&) = delete;
     WiredTigerUtil& operator=(const WiredTigerUtil&) = delete;
diff --git a/src/third_party/wiredtiger/src/conn/conn_compact.c b/src/third_party/wiredtiger/src/conn/conn_compact.c
index 78170b83667..44a2698da88 100644
--- a/src/third_party/wiredtiger/src/conn/conn_compact.c
+++ b/src/third_party/wiredtiger/src/conn/conn_compact.c
@@ -795,9 +795,15 @@ __wt_background_compact_signal(WT_SESSION_IMPL *session, const char *config)
     WT_ERR(__wt_config_merge(session, cfg, "background=", &stripped_config));
 
     /* The background compact configuration cannot be changed while it's already running. */
-    if (enable && running && strcmp(stripped_config, conn->background_compact.config) != 0)
-        WT_ERR_MSG(
-          session, EINVAL, "Cannot reconfigure background compaction while it's already running.");
+    if (enable && running && strcmp(stripped_config, conn->background_compact.config) != 0) {
+        if (session->event_handler->handle_general != NULL) {
+            ret = session->event_handler->handle_general(
+              session->event_handler, &conn->iface, &session->iface, WT_EVENT_COMPACT_RUNNING, NULL);
+            WT_ERR(EINVAL);
+        } else
+            WT_ERR_MSG(
+              session, EINVAL, "Cannot reconfigure background compaction while it's already running.");
+    }
 
     /* If we haven't changed states, we're done. */
     if (enable == running)
diff --git a/src/third_party/wiredtiger/src/include/wiredtiger.in b/src/third_party/wiredtiger/src/include/wiredtiger.in
index 2b23b525846..7e573a69e62 100644
--- a/src/third_party/wiredtiger/src/include/wiredtiger.in
+++ b/src/third_party/wiredtiger/src/include/wiredtiger.in
@@ -3437,6 +3437,7 @@ const char *wiredtiger_strerror(int error) WT_ATTRIBUTE_LIBRARY_VISIBLE;
 /*! WT_EVENT_HANDLER::special event types */
 typedef enum {
     WT_EVENT_COMPACT_CHECK, /*!< Compact check iteration. */
+    WT_EVENT_COMPACT_RUNNING, /*!< Compact was running when reconfigure was attempted. */
     WT_EVENT_CONN_CLOSE, /*!< Connection closing. */
     WT_EVENT_CONN_READY /*!< Connection is ready. */
 } WT_EVENT_TYPE;
