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

Possible Socket.SendFileAsync issue with files >2GiB. #41906

Closed
scalablecory opened this issue Sep 4, 2020 · 6 comments · Fixed by #42535
Closed

Possible Socket.SendFileAsync issue with files >2GiB. #41906

scalablecory opened this issue Sep 4, 2020 · 6 comments · Fixed by #42535
Assignees
Labels
area-System.Net.Sockets bug os-linux Linux OS (any supported distro)
Milestone

Comments

@scalablecory
Copy link
Contributor

Within our Unix code, we are casting FileStream.Length to an int here:

public static SocketError SendFileAsync(SafeSocketHandle handle, FileStream fileStream, Action<long, SocketError> callback) =>
SendFileAsync(handle, fileStream, 0, (int)fileStream.Length, callback);

This would fail for any files greater than 2GiB in length.

@ghost
Copy link

ghost commented Sep 4, 2020

Tagging subscribers to this area: @dotnet/ncl
See info in area-owners.md if you want to be subscribed.

@Dotnet-GitSync-Bot Dotnet-GitSync-Bot added the untriaged New issue has not been triaged by the area owner label Sep 4, 2020
@scalablecory scalablecory added os-linux Linux OS (any supported distro) and removed untriaged New issue has not been triaged by the area owner labels Sep 4, 2020
@geoffkizer
Copy link
Contributor

geoffkizer commented Sep 5, 2020

On Windows, TransmitFile is limited to 2GB. See https://docs.microsoft.com/en-us/windows/win32/api/mswsock/nf-mswsock-transmitfile

We may not need the same limitation for Linux, though.

@wfurt
Copy link
Member

wfurt commented Sep 5, 2020

Would it make sense to check file size and fall-back to some internal implementation if file is too big? That would give us consistency while preserving perf benefits when possible...

@geoffkizer
Copy link
Contributor

Possibly, yeah.

At the very least we should give a good exception here instead of just casting and losing the actual file length...

@wfurt
Copy link
Member

wfurt commented Sep 5, 2020

actually

The maximum number of bytes that can be transmitted using a single call to the TransmitFile function is 2,147,483,646, the maximum value for a 32-bit integer minus 1. The maximum number of bytes to send in a single call includes any data sent before or after the file data pointed to by the lpTransmitBuffers parameter plus the value specified in the nNumberOfBytesToWrite parameter for the length of file data to send. If an application needs to transmit a file larger than 2,147,483,646 bytes, then multiple calls to the TransmitFile function can be used with each call transferring no more than 2,147,483,646 bytes.

it seems like the correct way is to make multiple calls - and I'm not sure we do.

@stephentoub
Copy link
Member

it seems like the correct way is to make multiple calls - and I'm not sure we do.

I separated this out into #42534.

@ghost ghost locked as resolved and limited conversation to collaborators Dec 7, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.Net.Sockets bug os-linux Linux OS (any supported distro)
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants