This doesn't look like a problem with gRPC itself. The RpcException: Status(StatusCode=Unknown, Detail="Exception was thrown by handler.") only happens if the handler code (written by you) throws an exception. Under normal circumstances, handlers should not do that and if they the you as the author of the hander are responsible for what they throw. To me this looks like a problem in your code somewhere. I'd suggest wrapping the entire handler body in try .. catch(Exception e) block and see what lines throws the exception and then dealing with it based on what kind of exception it turns out to be (It's that info already in the logs?).
On Thursday, October 4, 2018 at 4:44:41 AM UTC+2, [email protected] wrote: > > Here is the server code > > class Program > { > static void Main(string[] args) > { > Server server = new Server > { > Services = { Logger.Logger.BindService(new LoggerImp()) }, > Ports = { new ServerPort("192.168.1.223", 50051, > ServerCredentials.Insecure) } > }; > server.Start(); > > > Console.WriteLine("Greeter server listening on port " + 50051 > ); > Console.WriteLine("Press any key to stop the server..."); > Console.ReadKey(); > > > server.ShutdownAsync().Wait(); > } > } > > > class LoggerImp : Logger.Logger.LoggerBase > { > private HashSet<IServerStreamWriter<LogMessage>> listeners = new > HashSet<IServerStreamWriter<LogMessage>>(); > > > public override Task ListenForMessages(LogListener request, > IServerStreamWriter<LogMessage> responseStream, ServerCallContext context) > { > return base.ListenForMessages(request, responseStream, context > ); > } > > > public override async Task SendLogMessages(IAsyncStreamReader< > LogMessage> requestStream, IServerStreamWriter<LogMessage> responseStream, > ServerCallContext context) > { > listeners.Add(responseStream); > > > while (await requestStream.MoveNext()) > { > var current = requestStream.Current; > if (current.ClientType == 1) > { > listeners.Add(responseStream); > } > > > foreach (IServerStreamWriter<LogMessage> listener in > listeners) > { > try > { > await listener.WriteAsync(current); > } > catch (Exception) > { > //client stream no longer exists so remove it > from list of active streams > listeners.Remove(listener); > } > > > } > } > } > } > > The server will throw an error on the line > > await listener.WriteAsync(current); > > if the stream is no longer active (ie. I stopped the wpf app, started it > again and the server tries to send a message to a stream that does not > exist) I expected this but when this happens this also throws that > RpcException in the Wpf app which I didn't think would happen because I am > catching the exception on the server when I try to write to the stream but > it still seems to propagate back to the client. > > What I am trying to do is keep a list of all streams of a certain client > type, these streams then see any message that comes in from any client. > > On Wednesday, October 3, 2018 at 4:28:10 PM UTC-4, Benjamin Krämer wrote: >> >> Looks to my like the server side threw an exception. Can you also paste >> the server side? >> > -- You received this message because you are subscribed to the Google Groups "grpc.io" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/grpc-io. To view this discussion on the web visit https://groups.google.com/d/msgid/grpc-io/a706689d-f8ed-49ff-ba96-755e9695fb8c%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.
