We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
我的业务逻辑是: ApiLogin 我希望在登录验证失败后,服务端确保连接要关闭掉 客户端发现失败的结果也做一层主动关闭
伪代码: server.ts
if(认证失败){ call.error("失败"); call.conn.close();//如果客户端立即关闭,这里会强制覆盖和返回一个错误(类似调用call.error),并且这里即使判断了conn的状态也是没用 }
client.ts
let ret = await ... if(!ret.succ){ client.disconnect(); }
服务端打印的日志如下:
<21632> 2022-02-14 15:20:02 [ERROR] 127.0.0.1 Conn#3 [Api:Send] SN=1 [SendReturnErr] WebSocket is not open: readyState 2 (CLOSING) { isSucc: false, err: TsrpcError { message: 'Content is empty', type: 'ApiError', code: 400 } } <21632> 2022-02-14 15:20:02 [ERROR] 127.0.0.1 Conn#3 [Api:Send] SN=1 { message: 'WebSocket is not open: readyState 2 (CLOSING)', name: 'SendReturnErr' } <21632> 2022-02-14 15:20:02 [ERROR] 127.0.0.1 Conn#3 [Api:Send] SN=1 [SendReturnErr] WebSocket is not opened { isSucc: false, err: TsrpcError { message: 'Internal Server Error', type: 'ServerError', code: 'INTERNAL_ERR', innerErr: 'WebSocket is not open: readyState 2 (CLOSING)' } } <21632> 2022-02-14 15:20:02 [INFO] 127.0.0.1 Conn#3 [Disconnected] Code=1000 ActiveConn=1
客户端打印日志如下:
[ApiReq] #1 Send {content: 'err'} Lost connection to ws://127.0.0.1:3000 code=1000 reason= [ApiErr] #1 Send TsrpcError {message: 'Lost connection to server', type: 'NetworkError', code: 'LOST_CONN'}
附带一个能重现问题的demo testConnClose.zip
The text was updated successfully, but these errors were encountered:
服务端改成这样即可:
if(认证失败){ await call.error("失败"); call.conn.close();//如果客户端立即关闭,这里会强制覆盖和返回一个错误(类似调用call.error),并且这里即使判断了conn的状态也是没用 }
即 先确保 call.error 发送完成,再关闭连接。
Sorry, something went wrong.
难怪,我还想说客户端不关闭连接都会出错 原来是异步error时,被下一行close影响导致的错误
No branches or pull requests
我的业务逻辑是: ApiLogin
我希望在登录验证失败后,服务端确保连接要关闭掉
客户端发现失败的结果也做一层主动关闭
伪代码:
server.ts
client.ts
服务端打印的日志如下:
客户端打印日志如下:
附带一个能重现问题的demo
testConnClose.zip
The text was updated successfully, but these errors were encountered: