@@ -143,7 +143,7 @@ Future<Void> processRequest(Reference<ExtConnection> ec,
143143 try {
144144 Reference<ExtMsg> msg = ExtMsg::create (header, body, finished);
145145 if (verboseLogging)
146- TraceEvent (" BD_processRequest" ).detail (" Message" , msg->toString ());
146+ TraceEvent (" BD_processRequest" ).detail (" Message" , msg->toString ()). detail ( " connId " , ec-> connectionId ) ;
147147 if (verboseConsoleOutput)
148148 fprintf (stderr, " C -> S: %s\n\n " , msg->toString ().c_str ());
149149 return msg->run (ec);
@@ -165,29 +165,44 @@ ACTOR Future<Void> popDisposedMessages(Reference<BufferedConnection> bc,
165165 }
166166}
167167
168+ ACTOR Future<Void> housekeeping (Reference<ExtConnection> ec) {
169+ try {
170+ loop {
171+ wait (delay (DOCLAYER_KNOBS->CURSOR_EXPIRY ));
172+ Cursor::prune (ec->cursors , false );
173+ }
174+ } catch (Error& e) {
175+ // This is the only actor responsible for all the cursors created
176+ // through this connection. Prune all the cursors before cancelling
177+ // this actor.
178+ if (e.code () == error_code_actor_cancelled)
179+ Cursor::prune (ec->cursors , true );
180+ throw ;
181+ }
182+ }
183+
168184ACTOR Future<Void> extServerConnection (Reference<DocumentLayer> docLayer,
169185 Reference<BufferedConnection> bc,
170186 int64_t connectionId) {
171187 if (verboseLogging)
172- TraceEvent (" BD_serverNewConnection" );
188+ TraceEvent (" BD_serverNewConnection" ). detail ( " connId " , connectionId) ;
173189
174190 state Reference<ExtConnection> ec = Reference<ExtConnection>(new ExtConnection (docLayer, bc, connectionId));
175191 state PromiseStream<std::pair<int , Future<Void>>> msg_size_inuse;
176192 state Future<Void> onError = ec->bc ->onClosed () || popDisposedMessages (bc, msg_size_inuse.getFuture ());
193+ state Future<Void> connHousekeeping = housekeeping (ec);
177194
178195 DocumentLayer::metricReporter->captureGauge (DocLayerConstants::MT_GUAGE_ACTIVE_CONNECTIONS,
179196 ++docLayer->nrConnections );
180197 try {
181- ec->startHousekeeping ();
182-
183198 loop {
184199 // Will be broken (or set or whatever) only when the memory we are passing to processRequest is no longer
185200 // needed and can be popped
186201 state Promise<Void> finished;
187202 choose {
188203 when (wait (onError)) {
189204 if (verboseLogging)
190- TraceEvent (" BD_serverClosedConnection" );
205+ TraceEvent (" BD_serverClosedConnection" ). detail ( " connId " , connectionId) ;
191206 throw connection_failed ();
192207 }
193208 when (wait (ec->bc ->onBytesAvailable (sizeof (ExtMsgHeader)))) {
0 commit comments