Skip to content

Commit

Permalink
Use rtc::ToString instead of std::to_string in `SocketAddress::Po…
Browse files Browse the repository at this point in the history
…rtAsString()`

Justification for this change is that `std::to_string` should be
avoided as it uses the user's locale and calls to it get serialized,
which is bad for concurrency.

My actual motivation for this is quite bizarre. Before this change,
with Zed's use of the LiveKit Rust SDK, I was getting connection
strings that were not valid utf-8, instead having a port of
`3\u0000\u0000\u001c\u0000`. I have not figured out how that could
happen or why this change fixes it.
  • Loading branch information
mgsloan committed Nov 26, 2024
1 parent dac8015 commit 08f7a70
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion rtc_base/socket_address.cc
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ std::string SocketAddress::HostAsSensitiveURIString() const {
}

std::string SocketAddress::PortAsString() const {
return std::to_string(port_);
return rtc::ToString(port_);
}

std::string SocketAddress::ToString() const {
Expand Down

1 comment on commit 08f7a70

@mgsloan
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Revisiting this when looking into zed-industries/zed#23247. I see Max opened an issue on Livekit's repo about challenges with linking other C code while also using livekit - livekit/rust-sdks#364 not sure how that was resolved. Maybe that's related to the need to have this patch?

Please sign in to comment.