Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,11 +114,14 @@ class Application extends EggApplication {
}

onClientError(err, socket) {
this.logger.error('A client (%s:%d) error [%s] occurred: %s',
socket.remoteAddress,
socket.remotePort,
err.code,
err.message);
// ignore when there is no http body, it almost like an ECONNRESET
if (err.rawPacket) {
this.logger.warn('A client (%s:%d) error [%s] occurred: %s',
socket.remoteAddress,
socket.remotePort,
err.code,
err.message);
}

if (typeof this.config.onClientError === 'function') {
const p = eggUtils.callFn(this.config.onClientError, [ err, socket, this ]);
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,10 @@
"main": "index.js",
"types": "index.d.ts",
"files": [
"index.js",
"lib",
"app",
"config",
"lib",
"index.js",
"index.d.ts"
],
"scripts": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
'use strict';

module.exports = app => {
app.get('/', function* () {
this.body = this.app.serverEmit;
Expand Down
25 changes: 23 additions & 2 deletions test/lib/cluster/app_worker.test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
'use strict';

const net = require('net');
const request = require('supertest');
const address = require('address');
const assert = require('assert');
const sleep = require('mz-modules/sleep');
const utils = require('../../utils');

const DEFAULT_BAD_REQUEST_HTML = `<html>
Expand Down Expand Up @@ -64,11 +66,12 @@ describe('test/lib/cluster/app_worker.test.js', () => {

describe('customized client error', () => {
let app;
before(() => {
beforeEach(() => {
app = utils.cluster('apps/app-server-customized-client-error');
app.debug();
return app.ready();
});
after(() => app.close());
afterEach(() => app.close());

it('should do customized request when HTTP request packet broken', async () => {
const version = process.version.split('.').map(a => parseInt(a.replace('v', '')));
Expand All @@ -91,6 +94,13 @@ describe('test/lib/cluster/app_worker.test.js', () => {
test2.request().path = '/foo bar';
await test2.expect(DEFAULT_BAD_REQUEST_HTML).expect(400);
});

it('should not log when there is no rawPacket', async () => {
await connect(app.port);
await sleep(1000);
app.expect('stderr', /HPE_INVALID_EOF_STATE/);
app.notExpect('stderr', /A client/);
});
});

describe('listen hostname', () => {
Expand Down Expand Up @@ -121,3 +131,14 @@ describe('test/lib/cluster/app_worker.test.js', () => {
});
});
});

function connect(port) {
return new Promise(resolve => {
const socket = net.createConnection(port, '127.0.0.1', () => {
socket.write('GET http://127.0.0.1:8080/ HTTP', () => {
socket.destroy();
resolve();
});
});
});
}