Skip to content

Commit 7098681

Browse files
committed
race condition error handling
If the old code threw an exception starting, it would remaing in a stopped state. This replicates that behavior. If the start process fails, it reverts back to `STOPPED` and does not remain in a `STARTING` state.
1 parent c9f42db commit 7098681

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

dxm/src/main/java/io/pcp/parfait/dxm/PcpMmvWriter.java

+10-5
Original file line numberDiff line numberDiff line change
@@ -348,12 +348,17 @@ private void doUpdateMetric(MetricName name, Object value) {
348348
public final void start() throws IOException {
349349
updateState(State.STARTING);
350350

351-
initialiseOffsets();
351+
try {
352+
initialiseOffsets();
352353

353-
dataFileBuffer = byteBufferFactory.build(getBufferLength());
354-
synchronized (globalLock) {
355-
populateDataBuffer(dataFileBuffer, metricData.values());
356-
preparePerMetricBufferSlices();
354+
dataFileBuffer = byteBufferFactory.build(getBufferLength());
355+
synchronized (globalLock) {
356+
populateDataBuffer(dataFileBuffer, metricData.values());
357+
preparePerMetricBufferSlices();
358+
}
359+
} catch (IOException | RuntimeException e) {
360+
updateState(State.STOPPED);
361+
throw e;
357362
}
358363

359364
updateState(State.STARTED);

0 commit comments

Comments
 (0)