Open ValeriyDolgov opened 4 months ago
How does your grpc service look like? Did you call onComplete?
Yes, I do. Text below is my GRPC server code of this func on the other service.
@Override
public void setAccountsForMerchant(AccountProto.CreateAccountsRequest request,
StreamObserver<AccountProto.AccountResponse> responseObserver) {
log.info("Received create accounts for merchant request rqID={}, clientId={}",
request.getRequestId(),
request.getClientId());
responseObserver.onNext(executeAndGetResponse(() -> {
accountService.createAccountsForMerchant(request.getClientId(), request.getContractFee());
var response = prepareResponse(0L, "", getJsonSuccess(true));
log.info(SET_ACCOUNTS_RESPONSE_LOG, SUCCESS_KEY, request.getRequestId(), request.getClientId());
return response;
}, request.getRequestId(), request.getClientId(), SET_ACCOUNTS_RESPONSE_LOG));
responseObserver.onCompleted();
}
a) Is the setAccountsForMerchant
function on the server called? Or does the call just hang elsewhere?
b) Is the responseObserver.onCompleted()
method on the server actually called? Maybe your executeAndGetResponse
blocks the code for longer than expected or throws an error.
No, the code that I provided above is from the service that I want to reach from the service that I described in the question above. When it comes to executing the .setAccountsForMerchant method
try {
return accountServiceBlockingStub .setAccountsForMerchant(getAccountBasicRequest(requestId, merchantId, contractFee));
} catch (Exception e) {
var message = String.format("Error when getting response from account-service: %s", e.getMessage());
log.error(message, e);
throw new AccountServiceResponseException(messageService.getMessage(ACCOUNT_SERVICE_NOT_AVAILABLE), 400);
}
my request just hangs. But as soon as I remove the GRPC server functionality from this service, everything goes well
Unless that is some weird issue regarding server address resolution, I don't have any idea what might cause this.
You could probably check the state of the client channel to verify that is actually connected and not in some kind of transient failure. Do you use a scheme in the client address e.g. dns:///foo.bar.test
? If not, you should.
[closed=[], open=[[buffered_nanos=4802324400, waiting_for_connection]]]
Set in application.yml
grpc:
client:
account-grpc-server:
address: dns:///ipaddress:port
enableKeepAlive: true
keepAliveWithoutCalls: true
negotiationType: plaintext
server:
port: 8081
Also didn't help
Hi everyone, we have had a similar experience since updating to v3.0.0. It's working on production, but locally, the client hangs forever when calling a gRPC server. After adding .withDeadlineAfter(5, TimeUnit.SECONDS)
I get the following messages:
2024-02-28T16:24:34.984+01:00 ERROR 54410 --- [***] [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet] : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed: io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: deadline exceeded after 4.978149667s. Name resolution delay 0.000143042 seconds. [closed=[], open=[[buffered_nanos=4978884666, waiting_for_connection]]]] with root cause
io.grpc.StatusRuntimeException: DEADLINE_EXCEEDED: deadline exceeded after 4.978149667s. Name resolution delay 0.000143042 seconds. [closed=[], open=[[buffered_nanos=4978884666, waiting_for_connection]]]
at io.grpc.stub.ClientCalls.toStatusRuntimeException(ClientCalls.java:268)
at io.grpc.stub.ClientCalls.getUnchecked(ClientCalls.java:249)
at io.grpc.stub.ClientCalls.blockingUnaryCall(ClientCalls.java:167)
The host is configured as localhost:4312
.
We reverted to v2.15.0 for now.
In my case if I turn down the grpc server app and I start the grpc client app, then as long as the grpc client request occurs before the ServletWebServerInitializedEvent (or any other spring boot event) then the client request will not hang and the deadline exceeded takes place.
One work around is to drop the deadline exceeded and use instead a ListenableFuture with the timeout moved to the future get method. `try { createSessionResponse = futureStub.createSession(createSessionRequest); final var createSessionResponseMessage = createSessionResponse.get(withDeadlineAfter, TimeUnit.MILLISECONDS);
return createSessionResponseMessage;
} catch (final CancellationException | ExecutionException | InterruptedException | TimeoutException e) {
// handle each error accordingly
}
`
I have tried ApplicationStartedEvent, ContextRefreshedEvent - same. The grpc client hangs.
In ClientCalls.java from the grpc-java project, the thread that sends that request is never woke up .... More precisely in blockingUnaryCall method executor.waitAndDrain does not timeout on the LockSupport.park call. And that because the execute method is not called to perform the unlock at LockSupport.unpark ....
Some form of reference is lost somehow or something else gets corrupted for a reason.
Unfortunately I could not go further than that.
I have Spring boot app v.3.2.1 and GRPC server and client in one app. Initially, when I wrote the service, I only had a GRPC client. Everything worked well until the moment when I added a GRPC server to the same service. After adding it, requests to the GRPC server are successful, but when trying to make a request through the GRPC client, the request simply freezes.
Dependencies i have in pom.xml
Applcation.yaml
In logs due request i have
I try to make requests locally, but i didn't help.
Update: I add deadline for this request:
After passing 5 seconds I received the following logs after the ones I sent earlier.