diff -uprN live/liveMedia/include/RTSPServer.hh live_modified/liveMedia/include/RTSPServer.hh
--- live/liveMedia/include/RTSPServer.hh	2021-05-03 15:42:11.000000000 +0200
+++ live_modified/liveMedia/include/RTSPServer.hh	2021-05-19 14:50:28.131635790 +0200
@@ -229,6 +229,7 @@ public: // should be protected, but some
     Authenticator fCurrentAuthenticator; // used if access control is needed
     char* fOurSessionCookie; // used for optional RTSP-over-HTTP tunneling
     unsigned fBase64RemainderCount; // used for optional RTSP-over-HTTP tunneling (possible values: 0,1,2,3)
+    unsigned fScheduledDelayedTask;
   };
 
   // The state of an individual client session (using one or more sequential TCP connections) handled by a RTSP server:
diff -uprN live/liveMedia/RTSPServer.cpp live_modified/liveMedia/RTSPServer.cpp
--- live/liveMedia/RTSPServer.cpp	2021-05-03 15:42:11.000000000 +0200
+++ live_modified/liveMedia/RTSPServer.cpp	2021-05-19 14:51:31.314731061 +0200
@@ -298,7 +298,7 @@ RTSPServer::RTSPClientConnection
   : GenericMediaServer::ClientConnection(ourServer, clientSocket, clientAddr),
     fOurRTSPServer(ourServer), fClientInputSocket(fOurSocket), fClientOutputSocket(fOurSocket),
     fAddressFamily(clientAddr.ss_family),
-    fIsActive(True), fRecursionCount(0), fOurSessionCookie(NULL) {
+    fIsActive(True), fRecursionCount(0), fOurSessionCookie(NULL), fScheduledDelayedTask(0) {
   resetRequestBuffer();
 }
 
@@ -938,7 +938,8 @@ void RTSPServer::RTSPClientConnection::h
   } while (numBytesRemaining > 0);
   
   --fRecursionCount;
-  if (!fIsActive) {
+  // If it has a scheduledDelayedTask, don't delete the instance or close the sockets. The sockets can be reused in the task.
+  if (!fIsActive && fScheduledDelayedTask <= 0) {
     if (fRecursionCount > 0) closeSockets(); else delete this;
     // Note: The "fRecursionCount" test is for a pathological situation where we reenter the event loop and get called recursively
     // while handling a command (e.g., while handling a "DESCRIBE", to get a SDP description).
diff -uprN live/liveMedia/RTSPServerRegister.cpp live_modified/liveMedia/RTSPServerRegister.cpp
--- live/liveMedia/RTSPServerRegister.cpp	2021-05-03 15:42:11.000000000 +0200
+++ live_modified/liveMedia/RTSPServerRegister.cpp	2021-05-19 14:53:35.760944718 +0200
@@ -244,6 +244,7 @@ void RTSPServer
     ParamsForREGISTER* registerParams = new ParamsForREGISTER(cmd, this, url, urlSuffix, reuseConnection, deliverViaTCP, proxyURLSuffix);
     envir().taskScheduler().scheduleDelayedTask(reuseConnection ? DELAY_USECS_AFTER_REGISTER_RESPONSE : 0,
 						(TaskFunc*)continueHandlingREGISTER, registerParams);
+    ++fScheduledDelayedTask;
   } else if (responseStr != NULL) {
     setRTSPResponse(responseStr);
     delete[] responseStr;
@@ -298,6 +299,8 @@ void RTSPServer::RTSPClientConnection::c
 }
 
 void RTSPServer::RTSPClientConnection::continueHandlingREGISTER1(ParamsForREGISTER* params) {
+  --fScheduledDelayedTask;
+
   // Reuse our socket if requested:
   int socketNumToBackEndServer = params->fReuseConnection ? fClientOutputSocket : -1;
 
@@ -309,6 +312,8 @@ void RTSPServer::RTSPClientConnection::c
     // deleting this.
     fClientInputSocket = fClientOutputSocket = -1; // so the socket doesn't get closed when we get deleted
     delete this;
+  } else if (!fIsActive && fRecursionCount <= 0 && fScheduledDelayedTask <= 0) {
+    delete this;
   }
   
   ourServer->implementCmd_REGISTER(params->fCmd,
