Commit Diff
- Commit:
30a624fb1ef8d2d9706a604cbf65dcdacf072e72
- From:
- Stefan Sperling <stsp@stsp.name>
- Date:
- Message:
- avoid a rename/stat race when gotd installs a new pack and then uses it Reset the cached repository's pack directory mtime after installing a new pack and pack index file. I have observed the mtime of the pack directory as reported by stat(2) remaining unchanged, until some time has passed beyond the rename(2) calls used to install the pack file and its index. If gotd immediately tries to read objects installed in a new pack file then the mtime reported by stat(2) might appear as unchanged. gotd will then fail to update its cached list of pack index files and not find the newly installed objects. Clearing the cached timestamp forces a readdir(3) call which does expose the newly installed pack index file as expected. Not sure whether stat(2) is supposed to immediately expose mtime changes after a rename(2). If so then this might warrant digging into the kernel. Seen while running regression tests for upcoming gotd notification support.
- Actions:
- Patch | Tree
--- gotd/repo_write.c +++ gotd/repo_write.c @@ -1715,6 +1715,12 @@ repo_write_dispatch_session(int fd, short event, void err->msg); break; } + /* + * Ensure we re-read the pack index list + * upon next access. + */ + repo_write.repo->pack_path_mtime.tv_sec = 0; + repo_write.repo->pack_path_mtime.tv_nsec = 0; } err = update_refs(iev); if (err) { --- gotd/session.c +++ gotd/session.c @@ -366,6 +366,10 @@ install_pack(struct gotd_session_client *client, const packidx_path); goto done; } + + /* Ensure we re-read the pack index list upon next access. */ + gotd_session.repo->pack_path_mtime.tv_sec = 0; + gotd_session.repo->pack_path_mtime.tv_nsec = 0; free(client->packidx_path); client->packidx_path = NULL;