Skip to content

How to implement System.IO.FileSystem.Watcher on FreeBSD #14716

Closed

Activity

  1. stephentoub commented on Jun 15, 2015

    @stephentoub
    Member

    Hopefully some OS-provided solution will work well, but worst case you could also consider a polling-based solution, e.g. https://github.com/dotnet/corefxlab/tree/master/src/System.IO.FileSystem.Watcher.Polling
    cc: @KrzysztofCwalina

  2. jonmill commented on Oct 6, 2015

    @jonmill
    Contributor

    I need to look again, but I believe the kqueue system works very similarly to the inotify system; if this is the case, we could potentially re-use the Linux implementation for FreeBSD. I'll dig in and find out more

  3. jonmill commented on Oct 7, 2015

    @jonmill
    Contributor

    It looks like the kqueue system requires opening a handle per file whereas Linux requires per directory. The Linux implementation won't work here so there are a couple options:

    1. Make a FreeBSD implementation using kqueues and error out if (read as when) the process hits the maximum handle limit
    2. Have the FreeBSD implementation have an external dependency on other software (an inotify port, other 3rd party FSW implementations, etc)
    3. Throw PlatformNotSupported for the FSW and kick the can down the road a bit

    If we want a robust implementation, I'd vote for looking into option 2 since my initial investigation showed that there are a few third-party libraries (runtime and compile time) that help with this problem...it would require customers install packages to use the FSW, however, but we already have precedence for that (OpenSSL for example).

    Thoughts?

  4. saper commented on Oct 8, 2015

    @saper
    Contributor

    kevent/kqueue is the best way and it's pretty easy in my opinion. So I'd go for option dotnet/corefx#1.

  5. jonmill commented on Feb 10, 2016

    @jonmill
    Contributor

    We have this throwing PlatformNotSupported right now but since FreeBSD work is mainly being done by the community, adding the Up-For-Grabs label

  6. janhenke commented on Feb 10, 2016

    @janhenke
    Member

    Fair enough. I would still like to see the FreeBSD port completed. Is there any strong opnion about the three possibilities you mentioned above?

  7. jonmill commented on Feb 10, 2016

    @jonmill
    Contributor

    @janhenke I think the kqueue implementation would be the best bet; it would be functionally similar to the FileSystemWatcher.Linux implementation but with FreeBSD nuances; it feels like the best option here unless FreeBSD has some special APIs (like OSX), but I don't know enough about FreeBSD to know that :)

  8. janhenke commented on Feb 11, 2016

    @janhenke
    Member

    I would then grab this one and try to come up with a kqueue based implementation.

  9. krytarowski commented on Feb 15, 2016

    @krytarowski
    Contributor

    @janhenke can you please try to reuse libinotify with CoreFX on FreeBSD? It's kevent(2)/kqueue(2) based and MIT licensed.

  10. janhenke commented on Feb 15, 2016

    @janhenke
    Member

    @krytarowski I'll look at it.

  11. janhenke commented on Apr 19, 2016

    @janhenke
    Member

    Sorry, I have to give this one back. My private life does not leave enough time for seriously getting into this.

  12. removed their assignment
    on Apr 19, 2016
  13. krytarowski commented on Apr 19, 2016

    @krytarowski
    Contributor

    I should be there soon with NetBSD

  14. 29 remaining items

  15. am11 commented on Apr 8, 2019

    @am11
    Member

    Would it make sense to tackle this old issue pragmatically for now? For example, port of KeventWatcher implementation from mono over to CoreFX, where the following options are available at https://github.com/mono/mono/blob/master/mcs/class/System/System.IO/, followed by CoreFX style adaptations.

    • DefaultWatcher.cs
    • FAMWatcher.cs
    • FileSystemWatcher.cs
    • KeventWatcher.cs
    • NullFileWatcher.cs

    To be able to build CoreFX recent master on FreeBSD, I tweaked some scripts and versions in CoreFX to ultimately use FreeBSD v3.x preview listed at https://github.com/dotnet/core-sdk/blob/master/README.md. However, CoreFX is currently using v2.2 of the SDK, and due to some API differences, I could not make much progress. Is there a patch available that we can apply on top of CoreFX master to build with SDK v3.x (any OS)?

  16. wolfspider commented on Apr 8, 2019

    @wolfspider

    @am11 If you move the 2.2 SDK folder into v3 does it not find it or is it not building? What happens when you try to build it?

  17. am11 commented on Apr 9, 2019

    @am11
    Member

    @wolfspider, with minimal patch: dotnet/corefx@master...am11:freebsd-ci, it downloads the SDK for FreeBSD, but subsequently fails while executing FindBestConfigurations MSBuild task:

    excerpt from: https://cirrus-ci.com/task/5635235873030144

    expand..
      Tool 'dotnet-reportgenerator-globaltool' (version '4.0.5') was successfully installed.
    /root/.nuget/packages/microsoft.dotnet.build.tasks.configuration/1.0.0-beta.19205.6/build/Microsoft.DotNet.Build.Tasks.Configuration.targets(106,5): error MSB4018: The "FindBestConfigurations" task failed unexpectedly. [/tmp/cirrus-ci-build/external/dir.proj]
    /root/.nuget/packages/microsoft.dotnet.build.tasks.configuration/1.0.0-beta.19205.6/build/Microsoft.DotNet.Build.Tasks.Configuration.targets(106,5): error MSB4018: System.ArgumentException: Unknown value 'freebsd' found in configuration 'netcoreapp-freebsd-Debug-x64'.  Expected property 'OSGroup' with one of values Windows_NT, Unix, Linux, OSX, FreeBSD, NetBSD, WebAssembly, AnyOS. [/tmp/cirrus-ci-build/external/dir.proj]
    /root/.nuget/packages/microsoft.dotnet.build.tasks.configuration/1.0.0-beta.19205.6/build/Microsoft.DotNet.Build.Tasks.Configuration.targets(106,5): error MSB4018:    at Microsoft.DotNet.Build.Tasks.Configuration.ConfigurationFactory.ParseConfiguration(String configurationString, Boolean permitUnknownValues, Configuration baseConfiguration) in /_/src/Microsoft.DotNet.Build.Tasks.Configuration/src/Configuration/ConfigurationFactory.cs:line 230 [/tmp/cirrus-ci-build/external/dir.proj]
    /root/.nuget/packages/microsoft.dotnet.build.tasks.configuration/1.0.0-beta.19205.6/build/Microsoft.DotNet.Build.Tasks.Configuration.targets(106,5): error MSB4018:    at Microsoft.DotNet.Build.Tasks.Configuration.FindBestConfigurations.Execute() in /_/src/Microsoft.DotNet.Build.Tasks.Configuration/src/FindBestConfigurations.cs:line 40 [/tmp/cirrus-ci-build/external/dir.proj]
    /root/.nuget/packages/microsoft.dotnet.build.tasks.configuration/1.0.0-beta.19205.6/build/Microsoft.DotNet.Build.Tasks.Configuration.targets(106,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/tmp/cirrus-ci-build/external/dir.proj]
    /root/.nuget/packages/microsoft.dotnet.build.tasks.configuration/1.0.0-beta.19205.6/build/Microsoft.DotNet.Build.Tasks.Configuration.targets(106,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/tmp/cirrus-ci-build/external/dir.proj]
    Build FAILED.
    /root/.nuget/packages/microsoft.dotnet.build.tasks.configuration/1.0.0-beta.19205.6/build/Microsoft.DotNet.Build.Tasks.Configuration.targets(106,5): error MSB4018: The "FindBestConfigurations" task failed unexpectedly. [/tmp/cirrus-ci-build/external/dir.proj]
    /root/.nuget/packages/microsoft.dotnet.build.tasks.configuration/1.0.0-beta.19205.6/build/Microsoft.DotNet.Build.Tasks.Configuration.targets(106,5): error MSB4018: System.ArgumentException: Unknown value 'freebsd' found in configuration 'netcoreapp-freebsd-Debug-x64'.  Expected property 'OSGroup' with one of values Windows_NT, Unix, Linux, OSX, FreeBSD, NetBSD, WebAssembly, AnyOS. [/tmp/cirrus-ci-build/external/dir.proj]
    /root/.nuget/packages/microsoft.dotnet.build.tasks.configuration/1.0.0-beta.19205.6/build/Microsoft.DotNet.Build.Tasks.Configuration.targets(106,5): error MSB4018:    at Microsoft.DotNet.Build.Tasks.Configuration.ConfigurationFactory.ParseConfiguration(String configurationString, Boolean permitUnknownValues, Configuration baseConfiguration) in /_/src/Microsoft.DotNet.Build.Tasks.Configuration/src/Configuration/ConfigurationFactory.cs:line 230 [/tmp/cirrus-ci-build/external/dir.proj]
    /root/.nuget/packages/microsoft.dotnet.build.tasks.configuration/1.0.0-beta.19205.6/build/Microsoft.DotNet.Build.Tasks.Configuration.targets(106,5): error MSB4018:    at Microsoft.DotNet.Build.Tasks.Configuration.FindBestConfigurations.Execute() in /_/src/Microsoft.DotNet.Build.Tasks.Configuration/src/FindBestConfigurations.cs:line 40 [/tmp/cirrus-ci-build/external/dir.proj]
    /root/.nuget/packages/microsoft.dotnet.build.tasks.configuration/1.0.0-beta.19205.6/build/Microsoft.DotNet.Build.Tasks.Configuration.targets(106,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [/tmp/cirrus-ci-build/external/dir.proj]
    /root/.nuget/packages/microsoft.dotnet.build.tasks.configuration/1.0.0-beta.19205.6/build/Microsoft.DotNet.Build.Tasks.Configuration.targets(106,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [/tmp/cirrus-ci-build/external/dir.proj]
        0 Warning(s)
        1 Error(s)
    Time Elapsed 00:00:30.48

    This was tested on FreeBSD 11.2. If we switch to FreeBSD 12.0 in CirrusCI YAML, we need to apply @wfurt's LD_PRELOAD workaround from https://github.com/dotnet/corefx/issues/1626#issuecomment-459842620. The reason why we still need to apply this workaround is because 3.0.100-preview-009812 is the last release for FreeBSD (from Jan).

    expand..
    --- a/.cirrus.yml
    +++ b/.cirrus.yml
    @@ -1,5 +1,5 @@
    freebsd_instance:
    -  image: freebsd-11-2-release-amd64
    +  image: freebsd-12-0-release-amd64
    
    freebsd_build_task:
    
    @@ -10,4 +10,4 @@ freebsd_build_task:
    
    build_script:
        - ./src/Native/build-native.sh   # this is redundant; just for testing native assets build beforehand
    -    - ./build.sh
    +    - LD_PRELOAD=/usr/lib/libpthread.so ./build.sh

    and it gives a different error about missing openssl (although there is no change in the package install step in .cirrus.yml):

    expand..
    Welcome to .NET Core!
    ---------------------
    GitHub: https://github.com/dotnet/core
    Docs: https://aka.ms/dotnet-docs
    HTTPS: https://aka.ms/aspnet-core-https
    Telemetry statement: https://aka.ms/dotnet-cli-telemetry
    System.TypeInitializationException: The type initializer for 'Crypto' threw an exception. ---> System.DllNotFoundException: Unable to load shared library 'System.Security.Cryptography.Native.OpenSsl' or one of its dependencies. In order to help diagnose loading problems, consider setting the LD_DEBUG environment variable: Shared object "libSystem.Security.Cryptography.Native.OpenSsl" not found, required by "dotnet"
    at Interop.Crypto.GetMaxMdSize()
    at Interop.Crypto..cctor()
    --- End of inner exception stack trace ---
    at Interop.Crypto.EvpSha256()
    at Internal.Cryptography.HashProviderDispenser.CreateHashProvider(String hashAlgorithmId)
    at System.Security.Cryptography.SHA256.Implementation..ctor()
    at System.Security.Cryptography.SHA256.Create()
    at Microsoft.DotNet.Cli.Telemetry.Sha256Hasher.Hash(String text)
    at Microsoft.DotNet.Cli.Telemetry.Sha256Hasher.HashWithNormalizedCasing(String text)
    at Microsoft.DotNet.Cli.Utils.ApplicationInsightsEntryFormat.<>c__DisplayClass10_0.<WithAppliedToPropertiesValue>b__1(KeyValuePair`2 p)
    at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
  18. wfurt commented on Apr 9, 2019

    @wfurt
    Member

    I think minimal implementation would be good. Having same behavior as Mono is also good as we are heading to convergence in general between corefx and Mono.

    As far as the build: I need to update build instructions.
    While back when I tested it, I could not build corefx with 3.0 even of supported platforms. That may have changed. As 3.0 looms closer I was unable to find enough time to keep everything up to date.

  19. josteink commented on Apr 10, 2019

    @josteink
    Member

    This was tested on FreeBSD 11.2. If we switch to FreeBSD 12.0 in CirrusCI YAML, we need to apply @wfurt's LD_PRELOAD workaround from #14537 (comment).

    I did submit a fix for this. Has there been no new “official” SDK build since then, or was the fix insufficient?

  20. am11 commented on Apr 10, 2019

    @am11
    Member

    Has there been no new “official” SDK build since then

    Seems like this is the case; FreeBSD was disabled in official SDK build matrix on January 8 due to some problems: dotnet/installer#248.


    I made a slight progress by applying dotnet/corefx#36766. The next errors are related to missing (preview5) runtime packages, ILAsm, CoreCLR and friends:

    error NU1102: Unable to find package runtime.freebsd-x64.Microsoft.NETCore.ILAsm with version (>= 3.0.0-preview5-27608-73)
    ..
    error NU1102: Unable to find package runtime.freebsd-x64.Microsoft.NETCore.Runtime.CoreCLR with version (>= 3.0.0-preview5-27608-73)

    To get unblocked, I think there are at least two possibilities:

    1. bootstrap new OS using source-build: https://github.com/dotnet/source-build/blob/master/Documentation/boostrap-new-os.md (defaults seem to be Linux-centric: https://cirrus-ci.com/task/6306235459567616)
    2. lobby dotnet/core-setup#5083 for internal build leg, based on @dagood's comment: (Re-enable FreeBSD builds once core-setup is building for FreeBSD again installer#248 (comment)). 8-)
  21. wfurt commented on Apr 10, 2019

    @wfurt
    Member

    This goes all the way to microsoft/azure-pipelines-agent#1906
    We need the agent to run the builds and without it it hard to push on infrastructure.

  22. danmoseley commented on Apr 30, 2019

    @danmoseley
    Contributor

    We can keep tracking this but it's not aligned to work on the 3.0 schedule

  23. josteink commented on Nov 9, 2019

    @josteink
    Member

    So we finally went with inotify instead of kqueue, just 4-5 years after I suggested so, because nobody wanted to implement the kqueue-version.

    Oh well. Better late than never. 😄

    Thanks @wfurt ! Good job!

  24. wfurt commented on Nov 9, 2019

    @wfurt
    Member

    This is mostly because @rootwyrm made me realized how easy it is. So we get some functionality now and we can improve if somebody bumps to issues.
    There is now wave of new effort to stabilize around 3.x and get source-build working for freebsd. I'll probably post update on main freebsd issue as it would be great to get help from anybody who has any time left. Even if that is to follow steps and provide feedback.

  25. rootwyrm commented on Nov 10, 2019

    @rootwyrm
    Contributor

    Ha, I will gladly take the blame here, and also deliver the very important caveats.

    The reason kqueue should remain preferred as a long term goal is that it's several orders of magnitude faster. libinotify is just a shim and may not be maintained. There's also the caveat of still missing O_SYMLINK. So IN_ATTRIB, IN_MODIFY, IN_MOVE_SELF, and IN_DELETE_SELF don't work. If you all would consider these important, I can see about making noises about finally accepting the kernel patches that fix this.

  26. transferred this issue fromdotnet/corefxon Jan 31, 2020
  27. added this to the 5.0 milestone on Jan 31, 2020
  28. ghost locked as resolved and limited conversation to collaborators on Jan 6, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.IOenhancementhelp wantedos-freebsd

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions