vapor-community / sockets

🔌 Non-blocking TCP socket layer, with event-driven server and client.
MIT License
575 stars 54 forks source link

send chunking #97

Closed tanner0101 closed 7 years ago

andreasley commented 7 years ago

Does this actually help with large transfers? I noticed that transfers fail in nonblocking mode if they are larger than the socket can handle. I've implemented nonblocking sending in my fork after trying something similar to this PR, which didn't work because the socket still was not ready to receive more data.

I was planning to create a PR for some changes anyway. https://github.com/vapor/socks/pull/95 already contains part of them, but nonblocking sending is more recent and not included there (yet).

tanner0101 commented 7 years ago

Right now the error occurs anytime more than ~260KB is returned in a response. Our error pages are ~500KB so they are failing to load entirely.

If you think there's a better way to implement this that we can do in a patch or minor fix let's do that. The overhead of chunking bytes with this solution is not ideal.

If not, we can postpone your solution for a later 1.x or 2.x and get this fix in sooner than later as it's a fairly critical issue.

Error

Server error: respond(Transport.StreamError.send("There was a problem while sending data.", Socket failed with code 0 ("Undefined error: 0") [sendFailedToSendAllBytes]))

Line Throwing Error

https://github.com/vapor/socks/blob/b42c03d0afdf0f6547efed3b274de4e8f393579b/Sources/SocksCore/TCPSocket.swift#L81

Bytes Sent vs. Length

bytes sent: 261676
bytes in data: 508903
jdmcd commented 7 years ago

When this does get merged, how do we go about getting these changes? Just vapor build --clean?

Casperhr commented 7 years ago

@mcdappdev yep vapor clean && vapor build

tanner0101 commented 7 years ago

@andreasley you're right. I'm also seeing failures above 2MB. Closing in favor of #101.