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

ENT-12414: New network protocol v4 - SAFEGET #5621

Closed
wants to merge 1 commit into from

Conversation

larsewi
Copy link
Contributor

@larsewi larsewi commented Oct 29, 2024

The current protocol (v3) uses a STAT <FILENAME> request to determine the file size (among other things), followed by a GET <FILENAME> request to fetch the file content. However, there is a race condition here. If the file size increases between the two requests, the client would think that the remaining data after the "file size" offset is a new response header.

Here, we introduce a new protocol-version "safeget" to address the race condition. PDUs from the response following a GET <FILENAME> request now contain a protocol header consisting of a NULL-byte terminated string of four unsigned integers (uint64_t). We will refer to the four integers as ERROR_CODE, FILE_SIZE, FILE_OFFSET, and PAYLOAD_SIZE. The integers will appear in this order in the protocol header. Each integer is separated by a whitespace character.

A non-zero ERROR_CODE signals that an error occurred. Furthermore, the exact value of ERROR_CODE specifies what went wrong on the server side. FILE_SIZE and FILE_OFFSET are mainly used to determine when the last PDU is received (i.e., when FILE_SIZE = FILE_OFFSET + PAYLOAD_SIZE). However, FILE_SIZE is also used to detect if the file is modified at the source during transmission. The payload starts immediately after the NULL-terminating byte in the protocol header and consists of PAYLOAD_SIZE bytes.

@larsewi larsewi added the WIP Work in Progress label Oct 29, 2024
@larsewi larsewi force-pushed the atomic branch 4 times, most recently from 63316a2 to 021a421 Compare October 29, 2024 13:25
The current protocol (v3) uses a `STAT <FILENAME>` request to determine
the file size (among other things), followed by a `GET <FILENAME>`
request to fetch the file content. However, there is a race condition
here. If the file size increases between the two requests, the client
would think that the remaining data after the "file size" offset is a
new response header.

Here, we introduce a new protocol-version "safeget" to address the race
condition. PDUs from the response following a `GET <FILENAME>` request
now contain a protocol header consisting of a NULL-byte terminated
string of four unsigned integers (`uint64_t`). We will refer to the four
integers as ERROR_CODE, FILE_SIZE, FILE_OFFSET, and PAYLOAD_SIZE. The
integers will appear in this order in the protocol header. Each integer
is separated by a whitespace character.

A non-zero ERROR_CODE signals that an error occurred. Furthermore, the
exact value of ERROR_CODE specifies what went wrong on the server side.
FILE_SIZE and FILE_OFFSET are mainly used to determine when the last PDU
is received (i.e., when FILE_SIZE = FILE_OFFSET + PAYLOAD_SIZE).
However, FILE_SIZE is also used to detect if the file is modified at the
source during transmission. The payload starts immediately after the
NULL-terminating byte in the protocol header and consists of
PAYLOAD_SIZE bytes.

Ticket: ENT-12414
Changelog: Fixed race condition when copying remote files.
Signed-off-by: Lars Erik Wik <[email protected]>
@larsewi
Copy link
Contributor Author

larsewi commented Nov 21, 2024

Superseded by #5629

@larsewi larsewi closed this Nov 21, 2024
@larsewi larsewi deleted the atomic branch December 3, 2024 14:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
WIP Work in Progress
Development

Successfully merging this pull request may close these issues.

1 participant