Problem description
The order of server stream events has changed since 1.10.0, which seems to have happened more specifically in #2650. Since these events are exposed publicly, it seems to me that this is a breaking change. We were relying on finish being emitted before cancelled in our code, but now cancelled is always emitted before finish even for normally finished streams that were not cancelled.
Reproduction steps
test.proto
syntax = "proto3";
package test;
service TestService {
rpc ping (Request) returns (stream Response) {}
}
message Request {}
message Response {}
index.js
const grpc = require('@grpc/grpc-js')
const loader = require('@grpc/proto-loader')
const definition = loader.loadSync(`${__dirname}/test.proto`)
const TestService = grpc.loadPackageDefinition(definition).test.TestService
const server = new grpc.Server()
server.bindAsync('0.0.0.0:9090', grpc.ServerCredentials.createInsecure(), () => {
server.addService(TestService.service, {
ping: stream => {
// Before 1.10.0 you get prefinish -> finish -> close -> cancelled
// After 1.10.0 you get prefinish -> cancelled -> finish -> close
stream.on('prefinish', () => console.log('prefinish'))
stream.on('cancelled', () => console.log('cancelled'))
stream.on('finish', () => console.log('finish'))
stream.on('close', () => console.log('close'))
stream.end()
setTimeout(() => server.forceShutdown())
}
})
server.start()
const client = new TestService(`localhost:9090`, grpc.credentials.createInsecure())
client.ping({}, () => {})
})
Environment
- OS name, version and architecture: macOS 14.1
- Node version: 18.12.2
- Node installation method: nvm
- If applicable, compiler version: N/A
- Package name and version:
@grpc/grpc-js 1.10.0
Additional context
Problem description
The order of server stream events has changed since 1.10.0, which seems to have happened more specifically in #2650. Since these events are exposed publicly, it seems to me that this is a breaking change. We were relying on
finishbeing emitted beforecancelledin our code, but nowcancelledis always emitted beforefinisheven for normally finished streams that were not cancelled.Reproduction steps
test.proto
index.js
Environment
@grpc/grpc-js1.10.0Additional context