Skip to content

Commit a650ba8

Browse files
committed
Claude feedback
1 parent dc48e11 commit a650ba8

1 file changed

Lines changed: 16 additions & 3 deletions

File tree

modules/dumbster/src/org/labkey/dumbster/model/DumbsterManager.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,10 @@ public static void setInstance(DumbsterManager instance)
6363
// The transport provider that was active before the recorder installed its own; restored on stop().
6464
private EmailTransportProvider _previousProvider;
6565

66+
// True while the recorder's capture provider is installed as the active provider. Guards against overwriting
67+
// _previousProvider if start() runs again after the capture server stopped on its own (without a stop() call).
68+
private boolean _recording;
69+
6670
public boolean start()
6771
{
6872
if (_server != null && !_server.isStopped())
@@ -72,13 +76,15 @@ public boolean start()
7276
return true;
7377
}
7478

75-
int port = -1;
79+
int port;
7680
try (ServerSocket socket = new ServerSocket(0))
7781
{
7882
port = socket.getLocalPort();
7983
}
80-
catch (IOException ignored)
84+
catch (IOException e)
8185
{
86+
_log.error("Failed to open a server socket", e);
87+
return false;
8288
}
8389

8490
_log.info("Connecting mail recorder to port {}", port);
@@ -102,7 +108,13 @@ public boolean start()
102108
recorderProvider.configure(props);
103109

104110
_log.info("Switching MailHelper to the mail recorder on port {}", port);
105-
_previousProvider = MailHelper.getActiveProvider();
111+
if (!_recording)
112+
{
113+
// Capture the real provider only when first entering the recording state; a restart after the capture
114+
// server stopped on its own must not overwrite it with a previously installed recorder provider.
115+
_previousProvider = MailHelper.getActiveProvider();
116+
_recording = true;
117+
}
106118
MailHelper.setActiveProvider(recorderProvider);
107119

108120
ContextListener.addShutdownListener(this);
@@ -117,6 +129,7 @@ public void stop()
117129
_log.info("Reverting MailHelper to {} configuration", AppProps.getInstance().getWebappConfigurationFilename());
118130
MailHelper.setActiveProvider(_previousProvider);
119131
_previousProvider = null;
132+
_recording = false;
120133

121134
_server.stop();
122135
ContextListener.removeShutdownListener(this);

0 commit comments

Comments
 (0)