Client lost data when service graceful shutdown
lealife opened this issue · 0 comments
lealife commented
service.js:
const cote = require('cote');
const timeService = new cote.Responder({ name: 'Time Service' });
timeService.on('time', (req, cb) => {
console.log('get', req.i)
setTimeout(() => {
cb(null, req.i);
console.log('return', req.i)
}, 5000)
});
// graceful shutdown
process.on('SIGINT', function() {
console.log('SIGINT signal received')
timeService.close(function() {
process.exit(0)
})
})
// graceful shutdown
process.on('SIGTERM', function() {
console.log('SIGTERM signal received')
timeService.close(function() {
process.exit(0)
})
})
client.js:
const cote = require('cote');
const client = new cote.Requester({ name: 'Client' });
let i = 0
async function test(argument) {
try {
i++
console.log('send', i)
// body...
let res = await client.send({ type: 'time', i })
console.log('get', res)
} catch(e) {
console.error('??', e)
}
}
setInterval(() => {
test()
}, 1000)
service log:
ime Service > service.online Client#7f0a955b-66ba-4cf4-b780-1525764e2c25
get 1
get 2
get 3
get 4
get 5
get 6
return 1
return 2
get 7
return 3
get 8
return 4
get 9
^CSIGINT signal received
return 5
return 6
return 7
return 8
return 9
ctrl+c shutdown the service, and it will response 5-9 to client. but the client doesn't receive 5-9 data
client log:
Hello! I'm Client#7f0a955b-66ba-4cf4-b780-1525764e2c25
========================
send 1
Client > service.online Time Service#87430ddc-3060-4cb7-aac9-a2ffa5bc4cf8 on 8000
send 2
send 3
send 4
send 5
send 6
get 1
send 7
get 2
get 3
send 8
get 4
send 9
send 10
send 11
send 12
send 13
send 14
send 15
Client > service.offline Time Service#87430ddc-3060-4cb7-aac9-a2ffa5bc4cf8 on 8000
send 16
send 17
send 18
send 19