Skip to content
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

fix: init every class member's value to defeat the redis-cli connection closed by pika #1390

Merged
merged 16 commits into from
Apr 26, 2023

Conversation

AlexStocks
Copy link
Collaborator

@AlexStocks AlexStocks commented Apr 22, 2023

fix #1367 : server 与 client 之间间歇性断开问题 https://github.com/OpenAtomFoundation/pika/issues/1367#issuecomment-1518607186。

问题代码所在:
image

这里构造函数,没见啥地方初始化 close_ 字段的值,但是它的值为 true。原因就在于 C++ 中如果不给变量初始化值,其值未定义,为 true 还是为 false 都有可能。

解决方法:在 class 中初始化成员变量的值。

@wanghenshui wanghenshui changed the title Feature/issue1367 fix #1367 Apr 22, 2023
@wanghenshui
Copy link
Collaborator

is ready?

@AlexStocks AlexStocks changed the title fix #1367 fix #1367: init every class member's value Apr 24, 2023
@AlexStocks AlexStocks changed the title fix #1367: init every class member's value fix #1367: init every class member's value to defeat the redis-cli connection closed by pika Apr 24, 2023
@@ -76,30 +78,36 @@ class NetConn : public std::enable_shared_from_this<NetConn> {

NetMultiplexer* net_multiplexer() const { return net_multiplexer_; }

std::string String() const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToString

@@ -20,13 +20,16 @@ class NetItem {

int fd() const { return fd_; }
std::string ip_port() const { return ip_port_; }
std::string String() const {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToString

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ToString

我这个是借鉴 Go 的实现,ToString() 是 Java 的吗?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

额接口名字而已,String也行,别的库基本都是ToString ToStringView to_string to_stringview 这几类

@wanghenshui wanghenshui changed the title fix #1367: init every class member's value to defeat the redis-cli connection closed by pika fix: init every class member's value to defeat the redis-cli connection closed by pika Apr 24, 2023
@AlexStocks
Copy link
Collaborator Author

@loveyacper Pls check it again. thx.

@AlexStocks AlexStocks merged commit 90033e1 into OpenAtomFoundation:unstable Apr 26, 2023
7 checks passed
bigdaronlee163 pushed a commit to bigdaronlee163/pika that referenced this pull request Jun 8, 2024
…on closed by pika (OpenAtomFoundation#1390)

* update version

* fix bug: wrong buffer size in vsnprintf

* fix holyThread close fd bug

* handle ewouldblock error

* add output macro

* init NetConn & RedisConn & ClientConn members' value in its class

* delete output macro

* delete ks.sh

* reformat output macro

* init NetConn & RedisConn & ClientConn members' value in its class

* add connection log

* recove GetTestDirectory

* do not init non-POD obj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

间隙性客户端pika断开
4 participants