序列化失败(grpc/节点) [英] Serialization failure (grpc/node)

查看:82
本文介绍了序列化失败(grpc/节点)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试遵循此处,以获取节点/grpc示例.我正在使用自己的原型文件,但是其余的代码看起来应该很熟悉.

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' }

我还无法真正找到一个如此具体的情况,我所能找到的使我相信这不是很好.根据,错误代码为13

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?

节点版本6.12.0

Node version 6.12.0

当我删除"call.write(request)"行时,客户端运行没有问题,因此它似乎源于该行代码.

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

推荐答案

该错误消息表示消息序列化(将传递给gRPC的消息对象转换为二进制数据)失败.通常发生这种情况是因为消息对象与预期的消息类型不匹配或无效.当前,此失败的错误消息在客户端或服务器上是相同的,因此它不会直接指示应归咎于谁.

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.

在该特定代码示例中,只有两行代码可以触发错误:客户端代码中的 call.write(request); call.write(response); 在服务器代码中.因此,这里最可能出现的问题是这些对象之一存在问题,或者这些对象之一的类型与方法签名所指示的类型不同.

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.

服务器发送的消息是由客户端发送的消息触发的,因此,缩小问题范围的一种方法是删除客户端中的 call.write(response)行.服务器代码.如果仍然出现错误,则问题出在客户端上,如果不是,则问题出在服务器上.

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.

这篇关于序列化失败(grpc/节点)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆