Zack
Zack

Reputation: 13972

Serialization failure (grpc/node)

I am attempting to follow the static codegen example as found here, for the node/grpc example. I'm using my own protofiles, but the rest of the code should look familiar.

'use strict'                                                                                                                                                                                                       

var messages = require('./time_series_pb.js');                                                                                                                                           
var services = require('./time_series_grpc_pb.js');                                                                                                                                      
var grpc = require('grpc');                                                                                                                                                                                        
var async = require('async');  

var client = new services.TimeSeriesServiceClient(                                                                                                                                                                 
    "localhost:50051",                                                                                                                                                                                             
    grpc.credentials.createInsecure()                                                                                                                                                                              
);                                                                                                                                                                                                                 

function getTimeSeries(callback) {                                                                                                                                                                                 

    var call = client.getTimeSeries();                                                                                                                                                                             

    call.on('data', function(data) {                                                                                                                                                                               
        console.log(data);                                                                                                                                                                                         
    });                                                                                                                                                                                                            
    call.on('end', callback);                                                                                                                                                                                      

    call.on('error', function(error) {                                                                                                                                                                             
        console.log(error);                                                                                                                                                                                        
    });                                                                                                                                                                                                            

    var request = new messages.GetTimeSeriesRequest();                                                                                                                                                             
    request.setName("foo");                                                                                                                                                                                        

    call.write(request);                                                                                                                                                                                           

    call.end();                                                                                                                                                                                                    

}                                                                                                                                                                                                                  


function main() {                                                                                                                                                                                                  
    async.series([                                                                                                                                                                                                 
        getTimeSeries                                                                                                                                                                                              
    ]);                                                                                                                                                                                                            
}                                                                                                                                                                                                                  

main(); 

I've got some server code as well.

'use strict'                                                                                                                                                                                                       

var messages = require('./time_series_pb.js');                                                                                                                                           
var services = require('./time_series_grpc_pb.js');                                                                                                                                      
var grpc = require('grpc');                                                                                                                                                                                        


function getTimeSeries(call) {                                                                                                                                                                                     
    call.on('data', function(request) {                                                                                                                                                                            
        var response = new messages.GetTimeSeriesResponse();                                                                                                                                                       
        response.setName("bar");                                                                                                                                                                                   
        call.write(response);                                                                                                                                                                                      
    });                                                                                                                                                                                                            
    call.on('error', function(error) {                                                                                                                                                                             
        console.log(error);                                                                                                                                                                                        
    });                                                                                                                                                                                                            
    call.on('status', function(status) {                                                                                                                                                                           
        console.log(status);                                                                                                                                                                                       
    });                                                                                                                                                                                                            
    call.on('end', function() {                                                                                                                                                                                    
        call.end();                                                                                                                                                                                                
    });                                                                                                                                                                                                            
}   

function getServer() {                                                                                                                                                                                             
    var server = new grpc.Server();                                                                                                                                                                                
    server.addService(services.TimeSeriesServiceService, {                                                                                                                                                                                                                                                                                                                   
        getTimeSeries: getTimeSeries                                                                                                                                                                               
    });                                                                                                                                                                                                            
    return server;                                                                                                                                                                                                 
}                                                                                                                                                                                                                  


function main() {                                                                                                                                                                                                  
    var server = getServer();                                                                                                                                                                                      
    server.bind('0.0.0.0:50051', grpc.ServerCredentials.createInsecure());                                                                                                                                         
    console.log("Starting server");                                                                                                                                                                                
    server.start();                                                                                                                                                                                                
}                                                                                                                                                                                                                  

main(); 

I can run the server code without issue, but when I try and connect with the client, I see the following stack trace.

{ Error: 13 INTERNAL: Serialization failure
at Object.exports.createStatusError (/home/nbkiq0w/getapi-platform/getapi-examples/node/node_modules/grpc/src/common.js:87:15)
at ClientDuplexStream._emitStatusIfDone (/home/nbkiq0w/getapi-platform/getapi-examples/node/node_modules/grpc/src/client.js:235:26)
at ClientDuplexStream._readsDone (/home/nbkiq0w/getapi-platform/getapi-examples/node/node_modules/grpc/src/client.js:201:8)
at /home/nbkiq0w/getapi-platform/getapi-examples/node/node_modules/grpc/src/client_interceptors.js:679:15
  code: 13,
 metadata: Metadata { _internal_repr: {} },
 details: 'Serialization failure' }

I haven't really been able to google a situation so specific, what I could find leads me to believe this isn't good. According to this, an error code of 13

Means some invariants expected by underlying system has been broken. If you see one of these errors, something is very broken.

I realize this isn't a ton to go on, so does anyone have any suggestions on how to debug this? How to get more verbose error output?

Node version 6.12.0

edit 1:

when I remove the "call.write(request)" line, the client runs without issue, so it appears to stem from that line of code.

Upvotes: 2

Views: 13520

Answers (1)

murgatroid99
murgatroid99

Reputation: 20297

That error message indicates that message serialization (transformation of the message object passed to gRPC into binary data) failed. This generally happens because the message object doesn't match the expected message type or is otherwise invalid. The error message for this failure is currently the same on the client or server, so it doesn't directly indicate which is to blame.

In that specific code sample, there are only two lines of code that could trigger the error: call.write(request); in the client code and call.write(response); in the server code. So the most likely problem here is either that something is wrong with one of those objects, or one of those objects has a different type than the method signature indicates that it should have.

The message sent by the server is triggered by the message sent by the client, so one way to narrow down where the problem is would be to remove the call.write(response) line in the server code. If you still get the error, the problem is on the client, and if not the problem is on the server.

Upvotes: 4

Related Questions