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

使用 example/02-kademlia/rendezvous_chat.cpp 遇到的问题 #231

Closed
Phypeng opened this issue Jan 23, 2024 · 1 comment
Closed

使用 example/02-kademlia/rendezvous_chat.cpp 遇到的问题 #231

Phypeng opened this issue Jan 23, 2024 · 1 comment

Comments

@Phypeng
Copy link

Phypeng commented Jan 23, 2024

Hi, 我是第一次使用 libp2p, 在测试 rendezvous_chat 时, FindProviders 总是获取不到 Provider.

所以我修改了日志级别为Debug, 发现 src/protocol/kademlia/impl/session.cpp 中的 Session::onMessageWritten 函数, 在写完业务数据包后, 立即尝试调用 close(), 导致 Client 认为链接被重置.

请评估是否可以按如下方法进行修改?

void Session::onMessageWritten(
    outcome::result<size_t> res,
    const std::shared_ptr<ResponseHandler> &response_handler) {
  if (not res) {
    close(res.as_failure());
    return;
  }

  --writing_;

  if (not response_handlers_.empty()) {
    read();
  }

  // if (canBeClosed()) {
  //   close();
  // }
}
@Phypeng
Copy link
Author

Phypeng commented Jan 24, 2024

我想了一下, 这样修改可能会导致连接不能及时断开. 这种问题的出现, 有以下几种可能:
1, 帧发生了乱序, 导致提前处理了FIN; //这种低级错误不至于现在才发现
2, 处理数据帧的使用了异步方法, 导致数据帧处理滞后; //这种处理是常规操作
3, 流状态处理存在问题. //大概率是这里的问题

所以我继续看了一下代码, 发现 YamuxStream::onFINReceived() 函数中, 接收到 FIN, 立刻将 is_readable_ 置为 false. 此时, 如果数据帧和FIN帧到达的时间间隔太小, 便会出现此问题.

@Phypeng Phypeng closed this as completed Jan 24, 2024
@Phypeng Phypeng reopened this Jan 24, 2024
@Phypeng Phypeng closed this as completed Jan 24, 2024
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

No branches or pull requests

1 participant