Skip to content

[Java][FlightRPC] FlightCallHeaders added to FlightClient::getStream aren't attached to call #33839

Closed

Description

@mkristofik

Describe the bug, including details regarding any error messages, version, and platform.

I'm using the Java flight-core version 10.0.1 and grpc-core version 1.50.2. I'm having trouble attaching headers to a GET call to a server.

Ticket ticket = new Ticket(/* ... */);
CallHeaders headers = new FlightCallHeaders();
headers.insert("foo", "bar");
CallOption opt = new HeaderCallOption(headers);
try (FlightStream stream = client.getStream(ticket, opt)) {
    // ...
}

I have logs that show the headers added to opt are not making it to the server. My best guess at why this happens is due to https://github.com/apache/arrow/blob/master/java/flight/flight-core/src/main/java/org/apache/arrow/flight/FlightClient.java#L309. FlightClient is ignoring the new stub returned by gRPC which has the header-injection interceptor added, see https://github.com/grpc/grpc-java/blob/master/stub/src/main/java/io/grpc/stub/MetadataUtils.java#L55.

Am I doing something wrong here?

Component(s)

FlightRPC, Java

Activity

  1. lidavidm commented on Jan 23, 2023

    @lidavidm
    Member

    Hmm, indeed. Are you interested in filing a PR? Else I'll try to fix this when I have a chance.

  2. changed the title [-]FlightCallHeaders added to FlightClient::getStream aren't attached to call[/-] [+][Java][FlightRPC] FlightCallHeaders added to FlightClient::getStream aren't attached to call[/+] on Jan 24, 2023
  3. mkristofik commented on Jan 24, 2023

    @mkristofik
    Author

    Here's the workaround I'm using, which seems to do what I want thus far. Could someone confirm whether this is a valid approach?

    private static class HeaderMiddleware implements FlightClientMiddleware {
        private final Map<String, String> headers;
    
        private HeaderMiddleware(Map<String, String> headers) {
            this.headers = headers;
        }
    
        @Override
        public void onBeforeSendingHeaders(CallHeaders outgoingHeaders) {
            for (Map.Entry<String, String> kv : headers.entrySet()) {
                outgoingHeaders.insert(kv.getKey(), kv.getValue());
            }
        }
    
        @Override public void onHeadersReceived(CallHeaders headers) { }
        @Override public void onCallCompleted(CallStatus status) { }
    
        static class Factory implements FlightClientMiddleware.Factory {
            Map<String, String> headers;
    
            Factory(Map<String, String> headers) {
                this.headers = headers;
            }
    
            @Override
            public FlightClientMiddleware onCallStarted(CallInfo info) {
                return new HeaderMiddleware(headers);
            }
        }
    }

    And then the construction of the client...

    BufferAllocator alloc = /* ... */
    Location loc = /* ... */
    Map<String, String> headers = /* ... */
    FlightClient client = FlightClient.builder(alloc, loc)
        .intercept(new HeaderMiddleware.Factory(headers))
        .build();
  4. lidavidm commented on Jan 24, 2023

    @lidavidm
    Member

    Yes, the middleware is perfectly fine. The call option is meant just to make it easier to attach headers for a particular call.

  5. added a commit that references this issue on Feb 27, 2023
    969dd29
  6. added a commit that references this issue on Oct 24, 2025
    23d0c51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions