-
Notifications
You must be signed in to change notification settings - Fork 3.6k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
GH-38096: [Java] FlightStream with metadata can cause error when closing #38110
GH-38096: [Java] FlightStream with metadata can cause error when closing #38110
Conversation
@lidavidm I was playing around with the DoExchange call and noticed a couple of issues. At first I was a little confused as to why So I noticed that you really need to call |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, just some nits
*/ | ||
public void getResult() { | ||
// After exchange is complete, make sure stream is drained to propagate errors through reader | ||
reader.next(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Possibly loop while reader.next()?
@@ -207,6 +207,8 @@ public void close() throws Exception { | |||
} else { | |||
AutoCloseables.close(closeables); | |||
} | |||
// Remove any metadata after closing to prevent negative refcnt | |||
applicationMetadata = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should this go in the finally instead? I suppose if this throws the application is unlikely to close again.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I put it here because if something throws and error before this, it's likely the buffer was not closed then. So at least this way, the buffer could be examined, but either way there is probably some resources leaked.
// After exchange is complete, make sure stream is drained to propagate errors through reader | ||
reader.next(); | ||
} | ||
|
||
/** Shut down the streams in this call. */ | ||
@Override | ||
public void close() throws Exception { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we drain the stream in close as well?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is drained already in the call to reader.close()
. From what I can tell, it will suppress any exception though. So probably better off draining with the call to getResult()
before closing to handle any errors, wdyt?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good.
We try to expose 'independent' readers/writers but in actuality in gRPC they are tied + the reader is the only source of errors (which in some sense makes sense, I suppose) so this is perhaps more of a mistake in our API design |
Makes sense, thanks for the explanation |
9849256
to
7740c76
Compare
…n closing (apache#38110) ### Rationale for this change The Java FlightStream can raise an error if metadata is transferred and ends up being closed twice. ``` java.lang.IllegalStateException: RefCnt has gone negative at org.apache.arrow.util.Preconditions.checkState(Preconditions.java:458) at org.apache.arrow.memory.BufferLedger.release(BufferLedger.java:130) at org.apache.arrow.memory.BufferLedger.release(BufferLedger.java:104) at org.apache.arrow.memory.ArrowBuf.close(ArrowBuf.java:1044) at org.apache.arrow.util.AutoCloseables.close(AutoCloseables.java:97) at org.apache.arrow.flight.FlightStream.close(FlightStream.java:208) ``` ### What changes are included in this PR? When FlightStream is closed, remove any reference of previous metadata to prevent reference count going negative if closed again. Also added `ExchangeReaderWriter.getResult()` for convenience and clear up ambiguity on error handling. ### Are these changes tested? Unit tests added for closing with metadata and ### Are there any user-facing changes? Added `ExchangeReaderWriter.getResult()` * Closes: apache#38096 Authored-by: Bryan Cutler <[email protected]> Signed-off-by: David Li <[email protected]>
Thanks @lidavidm ! |
After merging your PR, Conbench analyzed the 5 benchmarking runs that have been run so far on merge-commit 71a4ef4. There were no benchmark performance regressions. 🎉 The full Conbench report has more details. |
…n closing (apache#38110) ### Rationale for this change The Java FlightStream can raise an error if metadata is transferred and ends up being closed twice. ``` java.lang.IllegalStateException: RefCnt has gone negative at org.apache.arrow.util.Preconditions.checkState(Preconditions.java:458) at org.apache.arrow.memory.BufferLedger.release(BufferLedger.java:130) at org.apache.arrow.memory.BufferLedger.release(BufferLedger.java:104) at org.apache.arrow.memory.ArrowBuf.close(ArrowBuf.java:1044) at org.apache.arrow.util.AutoCloseables.close(AutoCloseables.java:97) at org.apache.arrow.flight.FlightStream.close(FlightStream.java:208) ``` ### What changes are included in this PR? When FlightStream is closed, remove any reference of previous metadata to prevent reference count going negative if closed again. Also added `ExchangeReaderWriter.getResult()` for convenience and clear up ambiguity on error handling. ### Are these changes tested? Unit tests added for closing with metadata and ### Are there any user-facing changes? Added `ExchangeReaderWriter.getResult()` * Closes: apache#38096 Authored-by: Bryan Cutler <[email protected]> Signed-off-by: David Li <[email protected]>
…n closing (apache#38110) ### Rationale for this change The Java FlightStream can raise an error if metadata is transferred and ends up being closed twice. ``` java.lang.IllegalStateException: RefCnt has gone negative at org.apache.arrow.util.Preconditions.checkState(Preconditions.java:458) at org.apache.arrow.memory.BufferLedger.release(BufferLedger.java:130) at org.apache.arrow.memory.BufferLedger.release(BufferLedger.java:104) at org.apache.arrow.memory.ArrowBuf.close(ArrowBuf.java:1044) at org.apache.arrow.util.AutoCloseables.close(AutoCloseables.java:97) at org.apache.arrow.flight.FlightStream.close(FlightStream.java:208) ``` ### What changes are included in this PR? When FlightStream is closed, remove any reference of previous metadata to prevent reference count going negative if closed again. Also added `ExchangeReaderWriter.getResult()` for convenience and clear up ambiguity on error handling. ### Are these changes tested? Unit tests added for closing with metadata and ### Are there any user-facing changes? Added `ExchangeReaderWriter.getResult()` * Closes: apache#38096 Authored-by: Bryan Cutler <[email protected]> Signed-off-by: David Li <[email protected]>
…n closing (apache#38110) ### Rationale for this change The Java FlightStream can raise an error if metadata is transferred and ends up being closed twice. ``` java.lang.IllegalStateException: RefCnt has gone negative at org.apache.arrow.util.Preconditions.checkState(Preconditions.java:458) at org.apache.arrow.memory.BufferLedger.release(BufferLedger.java:130) at org.apache.arrow.memory.BufferLedger.release(BufferLedger.java:104) at org.apache.arrow.memory.ArrowBuf.close(ArrowBuf.java:1044) at org.apache.arrow.util.AutoCloseables.close(AutoCloseables.java:97) at org.apache.arrow.flight.FlightStream.close(FlightStream.java:208) ``` ### What changes are included in this PR? When FlightStream is closed, remove any reference of previous metadata to prevent reference count going negative if closed again. Also added `ExchangeReaderWriter.getResult()` for convenience and clear up ambiguity on error handling. ### Are these changes tested? Unit tests added for closing with metadata and ### Are there any user-facing changes? Added `ExchangeReaderWriter.getResult()` * Closes: apache#38096 Authored-by: Bryan Cutler <[email protected]> Signed-off-by: David Li <[email protected]>
Rationale for this change
The Java FlightStream can raise an error if metadata is transferred and ends up being closed twice.
What changes are included in this PR?
When FlightStream is closed, remove any reference of previous metadata to prevent reference count going negative if closed again. Also added
ExchangeReaderWriter.getResult()
for convenience and clear up ambiguity on error handling.Are these changes tested?
Unit tests added for closing with metadata and
Are there any user-facing changes?
Added
ExchangeReaderWriter.getResult()