-
Notifications
You must be signed in to change notification settings - Fork 15
New issue
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
feat: close #7
feat: close #7
Conversation
lib/leader.js
Outdated
close() { | ||
this.removeAllListeners(); | ||
this._server.removeAllListeners(); | ||
this._server.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Server close,follower 也会优雅断开么?
那最后调用 client 的 close 就好了么。 如果多个 client,其中一个 client close 了,对应的 server 会关闭么 |
close 应该要支持同步和异步方式,例如有些 close 是需要去删除文件的,那么同步 close 实现不了。 |
默认用 promise 好了 |
close(callback) 吧 |
各管各吧 |
server 就一个端口,怎么各管各的? |
16bff7e
to
628cc32
Compare
如果是多个 client,要关闭所有的,不然剩下的会继续抢占端口。 当然也可以设计一个协议是专门关闭所有 client 的 |
每个 client 的 leader/follower 应该都是通过同一个 server 的端口来通讯的,那这个端口应该什么时候关闭呢? |
这个地方做起来是比较麻烦的,比较完美的办法是,server close 的时候只是从 typeSet 中移除记录,然后再遍历 typeSet + serverMap,如果发现 typeSet 中对于某个 port 来说找不到 serverMap 中对应监听的了就真正关闭 port。否则在多个应用一起跑的用例里面因为 close 可能会互相影响。 宗羽这块比较绕,我的思路对不 |
f224193
to
f4cf083
Compare
Codecov Report@@ Coverage Diff @@
## master #7 +/- ##
==========================================
+ Coverage 96.2% 96.51% +0.31%
==========================================
Files 15 15
Lines 658 718 +60
==========================================
+ Hits 633 693 +60
Misses 25 25
Continue to review full report at Codecov.
|
有点搞混,这个 port 是 client 对外的 port,还是 leader/follower 通讯的 port |
@popomore 我上面那个回复不对,理解错了。 现在知道怎么做了。当 leader close 的时候,需要:
|
f4cf083
to
3023b7c
Compare
为啥不影响,因为就一个单例? |
是的,全局有一个 map,对应 |
3023b7c
to
493e112
Compare
// close server if no one is listening on this port any more | ||
if (!listening) { | ||
const server = serverMap.get(port); | ||
yield server && server.close(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@gxcsoccer 这里做了最后的 close。如果没有 leader 在 listening port 的时候,做最后的关闭。这样就相互不打扰。
这个就是 close 的时候还没有 init 导致的 |
这个好奇怪,在 win 下 同样在 co 里时序好像不能保证 |
730ed09
to
f783127
Compare
同步讨论结果:
|
f783127
to
dd07415
Compare
cluster.close 是哪个对象?单例? |
单例 const cluster = require('cluster-client');
const client = cluster().create();
cluster.close(client); |
这句不是很懂,不通知咋等待? leader 是对外的通道,如果 leader 关了,follow 还有存在的必要? |
这个好像和 client.close 没本质区别?在 client.close 里也可以有相同实现。 |
没有存在的必要。
这个机制和原生的 net.Server#close 是比较相似的 |
内部实现是一样的。但是如果 close 方法挂载到 client 上,会导致如果 real client 上有 generator close 方法时,不能 delegate 到 client 上,这里就有潜规则了。如果用 cluster.close 就规避了这个问题。 |
@shaoshuai0102 好的,说的比较清楚了。可以在 egg cluster 模式下测下 close |
dd07415
to
64b4e5d
Compare
改好了 @gxcsoccer |
合并? |
@shaoshuai0102 再看一遍 |
好 egg 1.0 在等这个 |
lgtm |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
+1
lib/leader.js
Outdated
}); | ||
} | ||
|
||
setTimeout(reject, 30000); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
reject 应该有一个 err 吧?
64b4e5d
to
cd173ce
Compare
cd173ce
to
2ad1ec4
Compare
ci 过了 合并发布后 eggjs/egg#310 就可以过了 |
Checklist
npm test
passesAffected core subsystem(s)
Description of change