Skip to content
This repository has been archived by the owner on Apr 3, 2021. It is now read-only.

Remove intermediate buffering and solve the Read blocking issue #150

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

eycorsican
Copy link
Owner

No description provided.

Copy link

@fortuna fortuna left a comment

Choose a reason for hiding this comment

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

Thanks for addressing this!

C.tcp_shutdown(tpcb, 1, 0)
return C.ERR_OK
}
if len(buf) < int(p.tot_len) {
Copy link

Choose a reason for hiding this comment

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

This will break if the app passes a small buffer.

Instead of failing, why don't you copy as much as the buffer can hold, calling C.tcp_recved(tpcb, len(buf))?

Copy link
Owner Author

Choose a reason for hiding this comment

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

Calling tcp_recved only cause lwip to advertise a larger TCP window size, there is no way to partly receive a pbuf passed to tcpRecvFn, you either accept a whole pbuf and return ERR_OK, or reject it and return some other errors such as ERR_CONN, lwip would hold the pbuf for the next tcpRecvFn call in the latter case.

Copy link

Choose a reason for hiding this comment

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

I worry this new behavior would break any client that passes a buffer smaller than the TCP MSS, which seems to be the size of the pbufs. Actually it's worse: it will break if the buffer is shorter than the pbuf chain, since you're using the p.tot_len, not p.len.

I see you have to consume a full pbuf in order to return OK. In that case you could iterate until a full pbuf is read, then return OK.

Copy link
Owner Author

Choose a reason for hiding this comment

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

Then the blocking issue is re-introduced.

@oxtoacart
Copy link

I was playing around with this and noticed that sometimes I'd get a panic due to a send on a closed channel. I'll see if I can reproduce and get you more details.

@oxtoacart
Copy link

Here's the stack trace for the panic

github.com/eycorsican/go-tun2socks/core.(*tcpConn).Read(0xc000248090, 0xc000151200, 0x5dc, 0x5dc, 0x0, 0x0, 0x0)
	/Users/ox.to.a.cart/gocode/pkg/mod/github.com/eycorsican/[email protected]/core/tcp_conn.go:206 +0x12b

@eycorsican
Copy link
Owner Author

@oxtoacart Thanks for the information.

This is just a quick implementation trying to make the issues in #149 more clear, I'm not surprised there are bugs, it's not going to be merged.

@eycorsican eycorsican marked this pull request as draft December 11, 2020 22:19
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants