- Minor cosmetic changes to the Poll() datatypes
- Change the Poll() shim to return an Error instead of an errno.
The number of triggered file descriptors is now an output
parameter.
- Fix the implementation of Poll() to handle > 2 poll events.
This change is preparing for a future change that will move
Socket.{Select,Poll} to use `poll` instead of `select`.
Commit migrated from https://github.com/dotnet/corefx/commit/4b789b544cd66315a12ee81a214c5299f295c54c
After all of the shim work that's been done, the vast majority of corefx assemblies now are either platform-agnostic or have a Windows build and a Unix build, without further specialization based on OS in managed code. We do still have a few such assemblies, though (and this is unlikely to change any time soon):
- System.Diagnostics.Process
- System.IO.FileSystem.Watcher
- System.Net.NetworkInformation
- System.Runtime.InteropServices.RuntimeInformation
As a result, attempting to do a full build for Unix targets other than Linux or OS X currently results in compilation failures. This commit adds a new TargetsUnknownUnix property to the build as well as stub implementations that throw PlatformNotSupportedException for all of the missing functionality that causes such compilation errors.
With this change, doing ```build.cmd /p:SkipTests=true /p:OSGroup=FreeBSD" now completes successfully, as does ```build.cmd /p:SkipTests=true /p:OSGroup=Stephenix```.
Commit migrated from https://github.com/dotnet/corefx/commit/3e9f21b5f32e88925d97b928b9456f4cf8f5a1f5
Previously generations were strictly calculated. We had a set
of seed assemblies which defined generation boundaries based
on where they were supported. Eg: System.Runtime 4.0.0.0 was
supported inbox in Net45, 4.0.10.0 was supported inbox in
Net451, we could not OOB 4.0.0.0 to Net451 due to unification
so that defined a generation boundary.
All non-seed assemblies got the maximum generation
of all their transitive dependencies.
This worked fine, but created a confusing picture when
looking at the packages. New contracts that were only
implemented in DNXCore50 and Net46 had a reference assembly
that claimed to be dotnet5.1 even though they weren't
supported by any framework that was exclusive to 5.1-5.3.
It also meant that targeting a generation required that
someone use guardrails to ensure that they'd actually have
an implementation on any framework targeting that generation.
Without guardrails they might produce an assembly that would
not run on any framework of the generation it claimed.
This change raises the generation of all the reference assemblies
to a minimum that supports any implementation. This makes it
clear which generation of frameworks support the package,
it also lets someone target that generation without using guardrails
and guarantees that they'll at least run somewhere.
[tfs-changeset: 1543192]
Commit migrated from https://github.com/dotnet/corefx/commit/1c8144920c62e89f77567a16ebfa8c1324e52f07
A change was made to DNX to no longer restore project.jsons
that are in nested folders. This caused my batch update to miss
a number of tests and reference assembly projects.
This fixes the stale lock files, but restore is still broken.
[tfs-changeset: 1540448]
Commit migrated from https://github.com/dotnet/corefx/commit/3622cccc1b22fa1947a72d5126b59864e9d2fd0d
We need a new DNX to understand the latest packages.
We also need to move all "dotnet" projects to use dotnetX.X (generations)
now that the packages no longer have "dotnet" assets.
The new version of DNX dropped support for the aspnetcore
so I needed to update a few projects/packages that depended
on old package versions that had this moniker.
[tfs-changeset: 1540388]
Commit migrated from https://github.com/dotnet/corefx/commit/38f8d7a3ca1ee819c2b8eabb1c07ee4e99683c97
All projects that previously used dotnet have been updated to specify the appropriate generation of the surface area they depend on or in the case of desktop inbox contracts, the generation that includes the set of platforms they can support.
Now all packages contain all generations of API that they have ever shipped.
In doing this I needed to change how we determine package version. Before we ensured all assemblies would have the same version and used that. Now we choose the max.
Additionally I needed to change how we chose which asset to use for netcore50 when the dotnet asset was obscured by a placeholder for a previous netcore release (eg System.Runtime will have placeholders for Win8 since it was inbox there). To do this I wrote a task that uses nuget to evaluate the package assets with and without the placeholders. In this way it chooses the "best" dotnet implementation and reference assembly to use for netcore50.
This new model made my old MSBuild-based validation impossible to carry forward, so I wrote better validation in a task that actually uses Nuget's asset resolution algorithm. This uncovered many existing issues in packages that I have cleaned up. The validation algorithm could use some polish but its working now. Perf is not great, package build went from 15s to ~2 minutes. I'll work on this some more by making it incremental (input: nuspec, output: marker created on success). Profiling shows that most of the time is spent in calling the nuget APIs. I'll see if I can reduce some of this with caching for things that don't change (eg: RID graph). Ultimately I think its a reasonable tradeoff for the types of bugs I can find this way.
[tfs-changeset: 1539216]
Commit migrated from https://github.com/dotnet/corefx/commit/0931c347eb836c9da94d0d5ff9ad7a14403b9738
Array.Copy is implemented to work with any System.Array, not just T[]. When Array.Copy(sourceArr, destArray, length) is used, it delegates to Copy(sourceArr, sourceIndex, destArray, destIndex, length), and as such needs to query for the lower-bound of the supplied arrays, since although a T[] in C# always has a lower-bound of 0, an arbitrary Array may not. Given this, when calling Array.Copy, instead of calling Array.Copy(src, dest, length), it's slightly more efficient to just call Array.Copy(src, 0, dest, 0, length), avoiding the need for the GetLowerBound calls made while delegating to the 5-arg version.
I noticed one occurrence of this in some code I was looking at, and while fixing that, I fixed all of them across corefx\src.
Commit migrated from https://github.com/dotnet/corefx/commit/979026e435672e611e3f6e0647c873aa96ccc684
`build.cmd /p:LockDependencies=true` was the start of this change, but some errors with xunit build numbers led to all xunit upgrades being reset back to what they had in master.
project.json changes:
* System.Net.Security\src Switch off of explicit beta versioning, use the same baseline as everyone else. The S.S.C.Algorithms explicit upgrade is no longer required.
* System.Net.Requests\tests didn't build. Looking at the project.lock.json change, it appeared that a System.Net.Http reference was lost, restored it.
* System.Net.Http\tests didn't build. Looking at the project.lock.json change, it appeared that a System.IO.FileSystem reference was lost, restored it.
* System.Net.WebSockets.Client\src didn't build. Looking at the project.lock.json change, it appeared that a System.Collections (4.0.10) reference was lost, restored it.
* System.Diagnostics.TextWriterTraceListener\tests needed the runtime reference to load the correct System.Diagnostics.TraceSource binary.
Commit migrated from https://github.com/dotnet/corefx/commit/cec3a0f2db542bfa9d9c56bf988d966eacc35ad9
After the recent refactoring based on introducing native shims, the only reason there are special builds of System.IO.FileSystem and System.IO.FileSystem.DriveInfo for each of Linux and OS X is because of PathInternal.CaseSensitive/CaseInsensitive.cs, which just provides a hard-coded value as to whether the target platform is case-sensitive or case-insensitive-but-preserving. Similarly, these files are the only things forcing System.IO.Compression.ZipFile to not be completely platform-agnostic and to have separate Windows/Unix builds.
This commit recombines those assemblies by adding a platform-agnostic helper that simply creates a temporary file with upper-case letters and then checks whether that file can be found via the lower-cased version. This isn't perfect, in that it's possible to mount multiple file systems each with different case sensitivities, but a) it's better than the hardcoded version we currently have, and b) I don't know of any better portable solution.
(Issue dotnet/corefx#3156 tracks adding an API to provide information on case sensitivity. This change can be replaced by using such an API if/when it's available.)
Commit migrated from https://github.com/dotnet/corefx/commit/62ba788d4730be24cff0ff0432f43bcc7b9e4561
We were using -Wall but now use -Weverything and opt out of only
a handful of issues such as C++-98 compat, which we don't need.
The most notable impact is that the compiler now catches
narrowing implicit conversions, which was also the primary
motivation for doing this now as there was known debt in our
unsupervised usage of 64-bit types for sizes.
We now assert on bad buffer sizes *and* retain full checks in
release builds to be completely defensive against overflow.
We now use int32_t for scratch buffer sizes. int64_t remains for
file offsets and uint64_t remains for memory mapped files, but
int32_t for scratch eliminates a bunch of managed casts and
therefore makes it easier to reason about overflow prevention.
INT32_MAX is also the most portable limit on these buffer sizes
because the behavior of functions like read is only implementation
defined when the input size is greater than SSIZE_MAX and ssize_t
is int32_t on the lowest common denominator of modern platforms.
Enums corresponding to platform values are now enum X : T instead
of enum class X : T. The PAL_* names are descriptive enough without
scoping and the implicit conversion to raw integer is actually helpful
to avoid a bunch of casts, which are otherwise needed to interop with
the corresponding native API.
Commit migrated from https://github.com/dotnet/corefx/commit/648c01d69fba8d23750122d9823f53257785c8ca
The corefx build used an older beta5 version of DNX which hardcoded the path to bash in dnu, breaking the build on FreeBSD.
Updating DNX to the latest "stable" beta7 release fixes this.
After updating I noticed a few test projects didn't build anymore as they were missing some dependencies in project.json, added those.
Fixesdotnet/corefx#3173
Commit migrated from https://github.com/dotnet/corefx/commit/6df77fdbb6cf8e0d35a3074bb325f7810085daa3
- On Linux, FileSystemWatcher is built on top of inotify, which has various limits configured in the system for how many instances and watches can be created. When these limits are hit, exceptions are generated, but the Linux-provided error messages are cryptic about what the problem is. This change adds better error messages for those cases. It also ensures that errors regarding watch limits always come out of OnError rather than sometimes being thrown synchronously from EnableRaisingEvents and other times coming out asynchronously.
- As part of fixing that, I noticed that we had some reliability issues around marking the instance as enabled. I fixed this up to ensure that we only mark the instance as enabled when we've created everything we need to successfully launch it.
- While doing that, I noticed that on OS X, if we restart an FSW, we were unnecessarily re-creating a delegate. I changed it to avoid the unnecessary allocation.
- And while doing that, I also noticed that we we had a bad exception message when constructing an FSW with something other than a directory. I fixed the error message.
- I added tests for all these things.
Commit migrated from https://github.com/dotnet/corefx/commit/57cf111281a22feafb83854789680680da3cab50
This change updates the assembly versions of all of the corefx assemblies
as needed after we shipped stable versions. Assemblies with API differences
get a minor version bump. Assemblies with only bugfixes get a build version
bump.
In order to facilitate this I had to update the reference assemblies, so I took
the opportunity to port them all to the open.
[tfs-changeset: 1514419]
Commit migrated from https://github.com/dotnet/corefx/commit/40723b795917f2e98b64d45c17effb2546dd0cae
As part of the bug fix in https://github.com/dotnet/corefx/commit/dotnet/corefx@f2720abb758b50a9debb5ec146939ef6f5cef82d , a regression was introduced, one that we didn't catch until recently due to not having a test that stressed stopping and quickly restarting an FSW doing monitoring.
At the time of that fix, the active asynchronous monitoring operation didn't have its own copy of the directory handle; instead, it just used the single field on the FSW instance. As such, in a race condition between the asynchronous monitoring operation trying to use that instance and the main thread stopping the FSW and nulling out the field, the asynchronous monitoring operation could experience a NullReferenceException. The fix was to stop nulling out the field and just rely on closing the handle being enough to signal that monitoring should stop.
However, this causes a problem in a particular race condition. While a SafeHandle is in use by a P/Invoke operation, its reference count is temporarily incremented so as to prevent it from being closed while in use. This means that if the directory handle is disposed of while it's being used by ReadDirectoryChangesW, the handle's IsClosed won't return true until after ReadDirectoryChangesW returns. When the FSW is stopped, Dispose is called on the handle, and then when it's restarted, the handle's IsClosed is checked to see if there's currently an active monitoring operation, and if there is, the FSW assumes it doesn't need to restart anything. But if the stop and the start both occur during the call to ReadDirectoryChangesW, then the start won't actually start anything.
My reliability/performance fixes in https://github.com/dotnet/corefx/commit/dotnet/corefx@b6c478ccc9729e22ac7b9bf2248b644b51883db2 eliminated the reliance on the shared directory handle field: the asynchronous monitoring operation has its own copy. Thus, there's no longer a problem in nulling out the directory handle field. The fix for the regression is simply to do so.
(Long explanation for a fix that's simply to null out a field :-)
Commit migrated from https://github.com/dotnet/corefx/commit/6568da5ad7b4e5d516613f6a80865d5e88d72b31
When we're waiting for an event that we know will arrive, we can wait for a fairly long time, because if it doesn't arrive we're going to fail the tests anyway. This changes makes all of the ExpectEvent calls use a long timeout, much longer than most were previously using. In the process I removed all of the custom values being passed, as they were all the same or shorter than the new default. This should help to minimize avoid false positive flakiness.
Commit migrated from https://github.com/dotnet/corefx/commit/81e84b7910244f2f72ba760c100b16c01a38877c
My previous change to rename FSW test classes led to FSW tests getting parallelized. It turns out that some of the tests are not robust against this due to using file names that can end up conflicting with other tests. Additionally, it appears that the waiting / timeouts used by the tests is very susceptible to failure when run in parallel due to reliance on the shared thread pool, causing more failures in CI.
Commit migrated from https://github.com/dotnet/corefx/commit/83decea6937e1296be20202ff2f8ace51339e958
The FSW tests still take ~10 seconds on my machine, most of which is spent waiting for events to not fire. This change just separates the tests out so that they're not all on the same class, letting xunit parallelize them. They now take ~3.5 seconds on my machine.
Commit migrated from https://github.com/dotnet/corefx/commit/2fbabe417accb662a6ed63a40506dea0268cf8e2
One of the FSW tests is passing a 30 second timeout to an ExpectNoEvent, which means the test when correctly functioning will take at least 30 seconds. I've removed the custom timeout to give the test the normal timeout period of half a second.
Commit migrated from https://github.com/dotnet/corefx/commit/d4d0d561a3978f43ccb2271e8dc417d6d3ffefc2
At least on Windows 10, writing to a file can cause directories in its parent directory structure to also be noted as modified, such that events will be raised for those directories. This is causing the FileSystemWatcher_Changed_PreSeededNestedStructure test to consistently fail. I've updated the test to instead look for and modify file attributes, instead.
Commit migrated from https://github.com/dotnet/corefx/commit/784403a8cb1afa56136cdc4abd79a5425653c7d8
- Every iteration of calling ReadDirectoryChangesW was allocating a bunch of state (an FSWAsyncResult, a delegate, a new overlapped, etc). Fixed to allocate that state once and store it for the duration of the watching operation.
- Every iteration of calling ReadDirectoryChangesW was pinning/unpinning the buffer. Fixed to use a PreAllocatedOverlapped so that this happens just once for the whole operation.
- Centralized all of the cleanup code of the thread pool binding, and removed the thread pool binding field from the watcher as it's no longer necessary and it risks regressing to the code where we accidentally used the wrong one
- Removed confusing and duplicative flags around whether the implementation is currently running
- Removed duplicate interop code and moved the rest to the Common\src\Interop folder to follow the convention for the rest of the repo
- Made more robust the case where a failure occurs after creating the directory handle and before starting monitoring
- Removed unnecessary locking
- Reorganized some code to make the implementation easier to read, and added comments
Commit migrated from https://github.com/dotnet/corefx/commit/b6c478ccc9729e22ac7b9bf2248b644b51883db2
If a FileSystemWatcher is stopped and restarted while processing events, it can end up trying to free an allocated NativeOverlapped on the ThreadPoolBoundHandle associated with the new session even if it was created with the old one. This commit changes the code to store the appropriate binding and directory handle in locals and in the async state object so that the same binding can be used to free as was used to allocate.
Commit migrated from https://github.com/dotnet/corefx/commit/0f672042510d1902f7071189860c1960bd99ef43
inotify handles renames via a pair of MOVED_FROM and MOVED_TO events that are potentially delivered separately and that for some moves may not have a MOVED_TO at all (such as if moving a file out of the watched path). This means that if we get a MOVED_FROM and we haven't yet received any further events, we have a choice:
- Do we wait until we get another event to make a decision about how to process the MOVED_FROM, seeing if the next event is a MOVED_TO (in which case the MOVED_FROM is treated as part of the rename) or if it's something else (in which case the MOVED_FROM is treated as a deletion).
- Do we assume we won't get an associated MOVED_TO, and immediately treat the MOVED_FROM as a deletion.
We originally implemented the former, as it doesn't suffer from the race condition the latter suffers from, which might treat some MOVED_FROM/MOVED_TO pairs as a rename and others as a creation/deletion, based on timing. But it suffers from another problem, that if you just get a MOVED_FROM and no other event arrives (or arrives for a while) the event associated with the MOVED_FROM could be delayed (indefinitely if another event never arrives). dotnet/corefx#2587 switched from the former to the latter, under the assumption that it's the least bad of the two options.
As discussed at https://github.com/dotnet/corefx/pull/2655#issuecomment-128484923, a compromise can be to wait a few milliseconds for the MOVED_TO to arrive, as that's been shown to handle a vast majority of the cases where a MOVED_TO is on its way. This commit simply adds that timeout to our call to poll. As long as this code was being modified, the commit also adds a try/finally around the handle manipulation, just in case an exception happens to emerge.
Commit migrated from https://github.com/dotnet/corefx/commit/919d7af3f1277691c482bc0b7e35a510fe5fa370
On Linux, depending on the timing of events, we can sometimes generate
delete+create instead of rename. As such, we can't perform renames and
test that no create or delete is raised when we're running on Linux.
The issue had so far only arisen on the negative create test and not the
negative delete test, which turned out to be because the negative delete
test was using the wrong event name.
Commit migrated from https://github.com/dotnet/corefx/commit/56c279db8707bf9246109b1ff232925e0312b7f8