Skip to content

fix: pass O_SHARE_DELETE when digesting files - #8262

Merged
emillon merged 1 commit into
ocaml:mainfrom
emillon:fix-windows-open
Jul 27, 2023
Merged

emillon merged 1 commit into
ocaml:mainfrom
emillon:fix-windows-open

Conversation

@emillon

@emillon emillon commented Jul 24, 2023 •

Copy link
Copy Markdown
Collaborator

Fixes #8268

This flag corresponds to what Stdlib.open_in does. When passed, the files can be removed while they are still open. This condition can happen when background digests are enabled. This is a no-op everywhere else.

This allows enabling background digests on Windows.

@rgrinberg rgrinberg left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we leave the old code on Unix? Channels have mutexes that we don't really need here

@emillon

emillon commented Jul 25, 2023

Copy link
Copy Markdown
Collaborator Author

I'll try the other following approaches:

  • use Unix.open with _O_NOINHERIT
  • replace close by CloseHandle(Handle_val(v))

@emillon

emillon commented Jul 25, 2023

Copy link
Copy Markdown
Collaborator Author

Ah, even better: adding O_SHARE_DELETE at the open point fixes the issue (and is a noop on nonwindows). I'll update the PR.

@emillon
emillon force-pushed the fix-windows-open branch from e3754f1 to bccc862 Compare July 25, 2023 13:15
@emillon emillon changed the title WIP: fix: dune_digest: don't open with Unix module fix: pass O_SHARE_DELETE when digesting files Jul 25, 2023
@emillon
emillon marked this pull request as ready for review July 25, 2023 13:16
@emillon

emillon commented Jul 25, 2023

Copy link
Copy Markdown
Collaborator Author

There's still a part I don't completely understand (why the file is closed too late in some cases) but it might be related to the details of threading and win32unix.

@emillon
emillon requested a review from rgrinberg July 25, 2023 13:17
Comment thread src/dune_digest/dune_digest.ml Resolved
@rgrinberg
rgrinberg requested a review from nojb July 25, 2023 13:41

@nojb nojb left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

LGTM. Understanding why the file is not closed in the first place would be ideal of course, but this fix looks solid.

@emillon
emillon force-pushed the fix-windows-open branch from bccc862 to ae8941e Compare July 26, 2023 16:00
@emillon

emillon commented Jul 26, 2023

Copy link
Copy Markdown
Collaborator Author

I added a comment explaining the situation. let me know what you think.

Fixes ocaml#8268

This flag corresponds to what `Stdlib.open_in` does. When passed, the
files can be removed while they are still open. This condition can
happen when background digests are enabled. This is a no-op everywhere
else.

This allows enabling background digests on Windows.

Signed-off-by: Etienne Millon <[email protected]>
@emillon
emillon force-pushed the fix-windows-open branch from ae8941e to 86d940c Compare July 26, 2023 16:01
@nojb

nojb commented Jul 26, 2023

Copy link
Copy Markdown
Collaborator

I added a comment explaining the situation. let me know what you think.

LGTM

@hhugo

hhugo commented Jul 26, 2023

Copy link
Copy Markdown
Contributor

LGTM

@emillon
emillon merged commit d8bd6fa into ocaml:main Jul 27, 2023
@emillon
emillon deleted the fix-windows-open branch July 27, 2023 08:25
emillon added a commit to emillon/opam-repository that referenced this pull request Jul 28, 2023
CHANGES:

- Add `dune show rules` as alias of the `dune rules` command. (ocaml/dune#8000, @Alizter)

- Fix `%{deps}` to expand properly in `(cat ...)` when containing 2 or more
  items. (ocaml/dune#8196, @Alizter)

- Add `dune show installed-libraries` as an alias of the `dune
  installed-libraries` command. (ocaml/dune#8135, @Alizter)

- Fix the `severity` of error messages sent over RPC which was missing. (ocaml/dune#8193,
  @Alizter)

- Add `dune build --dump-gc-stats FILE` argument to dump garbage collection
  stats to a named file. (ocaml/dune#8072, @Alizter)

- Fix bug with ppx and Reason syntax due to missing dependency in sandboxed
  action (ocaml/dune#7932, fixes ocaml/dune#7930, @Alizter)

- Add `dune describe package-entries` to print all package entries (ocaml/dune#7480,
  @moyodiallo)

- Improve `dune describe external-lib-deps` by adding the internal dependencies
  for more information. (ocaml/dune#7478, @moyodiallo)

- Re-enable background file digests on Windows. The files are now open in a way
  that prevents race condition around deletion. (ocaml/dune#8262, fixes ocaml/dune#8268, @emillon)
emillon added a commit to emillon/opam-repository that referenced this pull request Jul 31, 2023
CHANGES:

- Add `dune show rules` as alias of the `dune rules` command. (ocaml/dune#8000, @Alizter)

- Fix `%{deps}` to expand properly in `(cat ...)` when containing 2 or more
  items. (ocaml/dune#8196, @Alizter)

- Add `dune show installed-libraries` as an alias of the `dune
  installed-libraries` command. (ocaml/dune#8135, @Alizter)

- Fix the `severity` of error messages sent over RPC which was missing. (ocaml/dune#8193,
  @Alizter)

- Add `dune build --dump-gc-stats FILE` argument to dump garbage collection
  stats to a named file. (ocaml/dune#8072, @Alizter)

- Fix bug with ppx and Reason syntax due to missing dependency in sandboxed
  action (ocaml/dune#7932, fixes ocaml/dune#7930, @Alizter)

- Add `dune describe package-entries` to print all package entries (ocaml/dune#7480,
  @moyodiallo)

- Improve `dune describe external-lib-deps` by adding the internal dependencies
  for more information. (ocaml/dune#7478, @moyodiallo)

- Re-enable background file digests on Windows. The files are now open in a way
  that prevents race condition around deletion. (ocaml/dune#8262, fixes ocaml/dune#8268, @emillon)
pmwhite pushed a commit to pmwhite/dune that referenced this pull request Aug 10, 2023
Fixes ocaml#8268

This flag corresponds to what `Stdlib.open_in` does. When passed, the
files can be removed while they are still open. This condition can
happen when background digests are enabled. This is a no-op everywhere
else.

This allows enabling background digests on Windows.

Signed-off-by: Etienne Millon <[email protected]>
pmwhite pushed a commit to pmwhite/dune that referenced this pull request Aug 10, 2023
Fixes ocaml#8268

This flag corresponds to what `Stdlib.open_in` does. When passed, the
files can be removed while they are still open. This condition can
happen when background digests are enabled. This is a no-op everywhere
else.

This allows enabling background digests on Windows.

Signed-off-by: Etienne Millon <[email protected]>
nberth pushed a commit to nberth/opam-repository that referenced this pull request Jun 18, 2024
CHANGES:

- Add `dune show rules` as alias of the `dune rules` command. (ocaml/dune#8000, @Alizter)

- Fix `%{deps}` to expand properly in `(cat ...)` when containing 2 or more
  items. (ocaml/dune#8196, @Alizter)

- Add `dune show installed-libraries` as an alias of the `dune
  installed-libraries` command. (ocaml/dune#8135, @Alizter)

- Fix the `severity` of error messages sent over RPC which was missing. (ocaml/dune#8193,
  @Alizter)

- Add `dune build --dump-gc-stats FILE` argument to dump garbage collection
  stats to a named file. (ocaml/dune#8072, @Alizter)

- Fix bug with ppx and Reason syntax due to missing dependency in sandboxed
  action (ocaml/dune#7932, fixes ocaml/dune#7930, @Alizter)

- Add `dune describe package-entries` to print all package entries (ocaml/dune#7480,
  @moyodiallo)

- Improve `dune describe external-lib-deps` by adding the internal dependencies
  for more information. (ocaml/dune#7478, @moyodiallo)

- Re-enable background file digests on Windows. The files are now open in a way
  that prevents race condition around deletion. (ocaml/dune#8262, fixes ocaml/dune#8268, @emillon)
@Alizter Alizter added this to the 3.10.0 milestone Jun 10, 2026
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.

background digests crash on Windows

5 participants