Skip to content

Commit

Permalink
chore: print req info if rpc server handleRequest failed (#53)
Browse files Browse the repository at this point in the history
  • Loading branch information
gxcsoccer committed Jun 20, 2019
1 parent 6630ed9 commit b1547fd
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/server/server.js
Expand Up @@ -252,7 +252,10 @@ class RpcServer extends Base {
const key = conn.remoteAddress;
this._connections.set(key, conn);
conn.on('request', req => {
this._handleRequest(req, conn).catch(err => { this.emit('error', err); });
this._handleRequest(req, conn).catch(err => {
err.req = req;
this.emit('error', err);
});
});
conn.once('close', () => { this._connections.delete(key); });
this.emit('connection', conn);
Expand Down
47 changes: 47 additions & 0 deletions test/server/server.test.js
@@ -1,12 +1,14 @@
'use strict';

const mm = require('mm');
const net = require('net');
const assert = require('assert');
const sleep = require('mz-modules/sleep');
const request = require('../../').test;
const dubboProtocol = require('dubbo-remoting');
const RpcClient = require('../../').client.RpcClient;
const RpcServer = require('../../').server.RpcServer;
const protocol = require('sofa-bolt-node/lib/protocol');
const ZookeeperRegistry = require('../../').registry.ZookeeperRegistry;

const logger = console;
Expand Down Expand Up @@ -60,6 +62,51 @@ describe('test/server.test.js', () => {
await server.close();
});

it('should handleRequest error', async () => {
server = new RpcServer({
appName: 'test',
registry,
logger,
});
await server.start();

const buf = protocol.requestEncode(1, {
serverSignature: null,
methodName: 'foo',
targetAppName: 'test',
args: [],
timeout: 3000,
}, {
protocolType: 'bolt',
codecType: 'hessian2',
boltVersion: 1,
sofaVersion: '',
crcEnable: false,
});
const socket = net.connect(12200, '127.0.0.1');
socket.write(buf);

try {
await server.await('error');
} catch (err) {
console.log(err);
assert(err.message.includes('Cannot read property \'split\' of null'));
assert(err.req);
assert(err.req.packetId === 1);
assert.deepEqual(err.req.data, {
methodName: 'foo',
serverSignature: null,
args: [],
methodArgSigs: [],
requestProps: null,
targetAppName: 'test',
});
}
socket.destroy();
await server.close();
});


describe('bolt', () => {
before(async function() {
server = new RpcServer({
Expand Down

0 comments on commit b1547fd

Please sign in to comment.