apache / apache/arrow

[C++][Flight] Unable to receive error status from DoPut

Open
#34,402 0 comments 0 reactions 0 assignees View on GitHub
Component: C++ Type: bug
Dominant language
C++
Stars
17.1k
Forks
4.3k
Avg merge
3d 18h
Merged PRs (30d)
91

Description

Hi I am am running into an issue where my Flight server DoPut is returning an error, but I am unable to receive it on the client side. Eventually after attempting to write data an exception is triggered on closing of the writer. And that exception was the error that should have been triggered at the time of calling DoPut. For my setup I am relying on the initial call (to client->DoPut) to authenticate and validate whether the client has write access. If successful the client would then proceed to write data via the writer. However in this scenario, my server has rejected the (DoPut) request and the client has no knowledge of this and attempts to proceed to write anyway. Does anyone know how I can retrieve the DoPut error right after the invocation? Below is a snippet of my issue

```
// Server side code that just returns an error
arrow::Status FlightServer::DoPut(const arrow::flight::ServerCallContext& context,
std::unique_ptr reader,
std::unique_ptr writer)
{
return flight::MakeFlightError(flight::FlightStatusCode::Failed, "Testing DoPut failure");
}
```

```
// Client side code
int client_main(int argc, char* argv[])
{
try {
run_do_put_test();
}
catch (const std::exception& e) {
std::cout << "Error running test: " << e.what() << std::endl;
return EXIT_FAILURE;
}

return EXIT_SUCCESS;
}

void run_do_put_test()
{
arrow::Status status = run_do_put_impl();
if (!status.ok())
throw std::runtime_error(status.message());
}

arrow::Status run_do_put_impl()
{
std::unique_ptr client;
ARROW_ASSIGN_OR_RAISE(flight::Location connect_location, flight::Location::ForGrpcTcp("0.0.0.0", 8001));
ARROW_ASSIGN_OR_RAISE(client, flight::FlightClient::Connect(connect_location));

auto do_put_input = get_input();
flight::FlightCallOptions call_options;
const auto fd = arrow::flight::FlightDescriptor::Command(do_put_input);

// The call to DoPut is expected to result in failure, but it doesn not...
ARROW_ASSIGN_OR_RAISE(auto result, client->DoPut(call_options, fd, get_schema()));

auto writer = std::move(result.writer);
auto metadata_reader = std::move(result.reader);
auto metadata = get_metadata();
const std::shared_ptr table = get_write_table();
arrow::TableBatchReader batch_reader(table);
while(true) {
std::shared_ptr batch;
ARROW_RETURN_NOT_OK(batch_reader.ReadNext(&batch));

if(!batch) {
break;
}
std::cout << "Attempting to write metadata" << std::endl;
ARROW_RETURN_NOT_OK(writer->WriteWithMetadata(*batch, metadata));
}

ARROW_RETURN_NOT_OK(writer->DoneWriting());
std::cout << "Done Writing" << std::endl;

// This next line is where the exception for DoPut will get triggered...
ARROW_RETURN_NOT_OK(writer->Close());
std::cout << "Closed Writer" << std::endl;

while(true) {
std::shared_ptr out_metadata;
ARROW_RETURN_NOT_OK(metadata_reader->ReadMetadata(&out_metadata));

if(!out_metadata) {
break;
}

std::cout << out_metadata->ToString() << std::endl;
}

return arrow::Status::OK();
}
```

Output from the program execution:

> Attempting to write metadata
> Done Writing
> Error running test: Testing DoPut failure. Detail: Failed. gRPC client debug context: {"created":"@1677625909.702169698","description":"Error received from peer ipv4:0.0.0.0:8001","file":"/src/core/lib/surface/call.cc","file_line":1041,"grpc_message":"Testing DoPut failure. Detail: Failed","grpc_status":2}. Client context: OK

### Component(s)

C++

Contributor guide

Open the contributing guide

Research direction

Start with FlightServer::DoPut and the client->DoPut call in the supplied reproducer, then trace writer->Close and metadata_reader->ReadMetadata. Reproduce the failure with the shown server and client code, and determine whether the DoPut error can be surfaced at invocation time; done means the client observes the rejection before attempting to write.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp, grpc
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.