# HG changeset patch # User Paul Boddie # Date 1645139617 -3600 # Node ID ffb9d9de40978d2f5df04f246318aca79008558b # Parent 85345ba9f3db3e15af244c0842f21d7518d35899 Attach to the provider before starting the thread to avoid a potential race condition where the resource is closed before the thread attaches to the provider. diff -r 85345ba9f3db -r ffb9d9de4097 libfsserver/lib/directories/directory_resource.cc --- a/libfsserver/lib/directories/directory_resource.cc Thu Feb 17 22:12:53 2022 +0100 +++ b/libfsserver/lib/directories/directory_resource.cc Fri Feb 18 00:13:37 2022 +0100 @@ -72,11 +72,6 @@ { DirectoryAccessor *accessor = provider->accessor(); - /* Attach to the provider to keep it available, even if the directory - resource is released. */ - - provider->attach(); - /* Invoke the directory reading mechanism. */ accessor->read_directory(writer); @@ -113,6 +108,11 @@ reader->ref = L4_INVALID_CAP; file_close(reader); + /* Attach to the provider to keep it available, even if the directory + resource is released. */ + + _provider->attach(); + /* Initiate the reading process. */ std::thread(read_directory, _provider, fileid, writer).detach();