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

fix(sendfile): reuse fd before fallback #8234

Merged
merged 1 commit into from
Jul 24, 2023
Merged

Conversation

emillon
Copy link
Collaborator

@emillon emillon commented Jul 19, 2023

Fixes #8210

If the sendfile branch failed, it left an empty target file.
This file needs to be removed, otherwise the next open call can fail if the file is not writeable.

@@ -179,6 +179,7 @@ module Copyfile = struct
let sendfile_with_fallback ?chmod ~src ~dst () =
try sendfile ?chmod ~src ~dst ()
with Unix.Unix_error (EINVAL, "sendfile", _) ->
Unix.unlink dst;
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this the correct place to do this, or can it be done inside sendfile when it aborts?

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think there is some similar cleanup for src there too.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I thought as well, but this happens in the prepare phase, not when sendfile itself fails.

@emillon emillon marked this pull request as ready for review July 19, 2023 13:15
@emillon emillon mentioned this pull request Jul 19, 2023
10 tasks
Copy link
Member

@rgrinberg rgrinberg left a comment

Choose a reason for hiding this comment

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

Thanks. This is indeed simpler.

Fixes ocaml#8210

If the `sendfile` branch failed, it leaves an empty target file, so
retrying will fail. Instead we reuse the fd directly.

Signed-off-by: Etienne Millon <me@emillon.org>
@emillon emillon merged commit cb3489d into ocaml:main Jul 24, 2023
@emillon emillon deleted the fix-8210 branch July 24, 2023 14:24
@emillon emillon mentioned this pull request Jul 25, 2023
7 tasks
@emillon emillon changed the title fix(sendfile): unlink dst before fallback fix(sendfile): reuse fd before fallback Jul 25, 2023
emillon added a commit to emillon/dune that referenced this pull request Jul 25, 2023
Fixes ocaml#8210

If the `sendfile` branch failed, it leaves an empty target file, so
retrying will fail. Instead we reuse the fd directly.

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to emillon/dune that referenced this pull request Jul 25, 2023
Fixes ocaml#8210

If the `sendfile` branch failed, it leaves an empty target file, so
retrying will fail. Instead we reuse the fd directly.

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit that referenced this pull request Jul 25, 2023
* test: repro for #8210 (EACCESS if sendfile fails)

What's happening here is:

- input and output files are open
- sendfile is attempted and fails
- both files are closed
- input file is opened again
- output file is opened again (but already exists)

This throws an error if the output file is not writable.

Signed-off-by: Etienne Millon <me@emillon.org>

* refactor: use Exn.protect instead of protectx (#8235)

This adds a layer of rebinding that obscures what is going on.

Signed-off-by: Etienne Millon <me@emillon.org>

* fix(sendfile): unlink dst before fallback (#8234)

Fixes #8210

If the `sendfile` branch failed, it leaves an empty target file, so
retrying will fail. Instead we reuse the fd directly.

Signed-off-by: Etienne Millon <me@emillon.org>

---------

Signed-off-by: Etienne Millon <me@emillon.org>
emillon added a commit to emillon/opam-repository that referenced this pull request Jul 25, 2023
CHANGES:

- Disable background digests on Windows. This prevents an issue where
  unremovable files would make dune crash when the shared cache is enabled.
  (ocaml/dune#8243, fixes ocaml/dune#8228, @emillon)

- Fix permission errors when `sendfile` is not available (ocaml/dune#8234, fixes ocaml/dune#8120,
  @emillon)
pmwhite pushed a commit to pmwhite/dune that referenced this pull request Aug 10, 2023
Fixes ocaml#8210

If the `sendfile` branch failed, it leaves an empty target file, so
retrying will fail. Instead we reuse the fd directly.

Signed-off-by: Etienne Millon <me@emillon.org>
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

- Disable background digests on Windows. This prevents an issue where
  unremovable files would make dune crash when the shared cache is enabled.
  (ocaml/dune#8243, fixes ocaml/dune#8228, @emillon)

- Fix permission errors when `sendfile` is not available (ocaml/dune#8234, fixes ocaml/dune#8120,
  @emillon)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

_build/default/bin/dune.exe: Permission denied (ecryptfs, Mint)
3 participants