@@ -45,6 +45,7 @@ public enum State {
4545 private final UnsafeBuffer headerBuffer = new UnsafeBuffer ();
4646 private long countersStartTimestamp = -1 ;
4747 private long countersPid = -1 ;
48+ private long countersValuesBufferLength = -1 ;
4849 private CountersReader countersReader ;
4950 private State state = State .CLOSED ;
5051
@@ -119,6 +120,12 @@ private int init() {
119120 headerBuffer .wrap (countersByteBuffer , 0 , LayoutDescriptor .HEADER_LENGTH );
120121 countersStartTimestamp = LayoutDescriptor .startTimestamp (headerBuffer );
121122 countersPid = LayoutDescriptor .pid (headerBuffer );
123+ countersValuesBufferLength = LayoutDescriptor .countersValuesBufferLength (headerBuffer );
124+
125+ if (countersValuesBufferLength <= 0 ) {
126+ state (State .CLEANUP );
127+ return 0 ;
128+ }
122129
123130 countersReader =
124131 new CountersReader (
@@ -174,7 +181,7 @@ private boolean isActive(File countersFile) {
174181 LOGGER .warn ("[{}] {} has not sufficient length" , roleName (), countersFile );
175182 return false ;
176183 }
177- if (countersStartTimestamp != -1
184+ if (countersValuesBufferLength != -1
178185 && !LayoutDescriptor .isCountersActive (
179186 headerBuffer , countersStartTimestamp , countersPid )) {
180187 LOGGER .warn ("[{}] {} is not active" , roleName (), countersFile );
@@ -193,6 +200,7 @@ private int cleanup() {
193200 countersFile = null ;
194201 countersStartTimestamp = -1 ;
195202 countersPid = -1 ;
203+ countersValuesBufferLength = -1 ;
196204
197205 State previous = state ;
198206 if (previous != State .CLOSED ) { // when it comes from onClose()
0 commit comments