@@ -56,24 +56,31 @@ def invoke_service(service, handler_method, input, output, call)
5656 end
5757
5858 # Mark trailers and add status (if not already set by handler):
59- if call . response &.headers
60- call . response . headers . trailer!
61-
59+ if headers = call . response &.headers
6260 # Only add OK status if grpc-status hasn't been set by the handler:
63- unless call . response . headers [ "grpc-status" ]
64- Protocol ::GRPC ::Metadata . add_status! ( call . response . headers , status : Protocol ::GRPC ::Status ::OK )
61+ unless headers [ "grpc-status" ]
62+ Protocol ::GRPC ::Metadata . add_status! ( headers , status : Protocol ::GRPC ::Status ::OK )
6563 end
6664 end
6765 end
6866
6967 def dispatch_to_service ( service , handler_method , input , output , call , deadline , parent : Async ::Task . current )
7068 if deadline
71- parent . with_timeout ( deadline ) do
69+ parent . with_timeout ( deadline . remaining ) do
7270 invoke_service ( service , handler_method , input , output , call )
7371 end
7472 else
7573 invoke_service ( service , handler_method , input , output , call )
7674 end
75+ rescue Async ::TimeoutError
76+ # Close input and output streams:
77+ input . close
78+ output . close_write unless output . closed?
79+
80+ # Set DEADLINE_EXCEEDED status in trailers:
81+ if headers = call . response &.headers
82+ Protocol ::GRPC ::Metadata . add_status! ( headers , status : Protocol ::GRPC ::Status ::DEADLINE_EXCEEDED , message : "Deadline exceeded" )
83+ end
7784 end
7885
7986 # Dispatch the request to the appropriate service.
0 commit comments