Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WaitHandle.WaitAny returns invalid result #9089

Closed
EgorBo opened this issue Jun 9, 2018 · 4 comments
Assignees
Projects

Comments

@EgorBo
Copy link
Member

@EgorBo EgorBo commented Jun 9, 2018

Steps to Reproduce

The following code should print "0" (array index of the object that satisfied the wait)

using System;
using System.Threading;

namespace ConsoleApplication11
{
    internal class Program
    {
        public static void Main()
        {         
            ManualResetEvent[] wh = new ManualResetEvent[2];
            wh[0] = new ManualResetEvent(true);
            wh[1] = wh[0];

            Console.WriteLine(WaitHandle.WaitAny(wh));
        }      
    }   
}

Current Behavior

The code prints:

2147483647

Expected Behavior

Should print 0 (just like .NET Core 2.1 does)

On which platforms did you notice this

[x] macOS
[ ] Linux
[ ] Windows

UPD:

Also, WaitAll instead of WaitAny in this case should throw ArgumentException (mono doesn't throw).

@marek-safar marek-safar added this to Bugs Pool in Bugs Week via automation Jun 11, 2018
@jaykrell jaykrell self-assigned this Jun 11, 2018
@lewurm lewurm moved this from Bugs Pool to In Progress in Bugs Week Jun 12, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 13, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 13, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 13, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 13, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 13, 2018
@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented Jun 13, 2018

I believe we malfunction on all the platforms, even Windows somewhat.

jaykrell added a commit to jaykrell/mono that referenced this issue Jun 14, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 14, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 14, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 14, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 15, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 16, 2018
jaykrell added a commit to jaykrell/mono that referenced this issue Jun 18, 2018
@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented Aug 13, 2018

Fix sitting in PR for months. #9114

@jaykrell

This comment has been minimized.

Copy link
Collaborator

@jaykrell jaykrell commented Sep 14, 2018

Fix sitting in PR for months. #9114

jaykrell added a commit to jaykrell/mono that referenced this issue Sep 14, 2018
@marek-safar

This comment has been minimized.

Copy link
Member

@marek-safar marek-safar commented Sep 21, 2018

@lateralusX could you please review the fix

Bugs Week automation moved this from In Progress to Done Sep 22, 2018
jaykrell added a commit that referenced this issue Sep 22, 2018
* mono_w32handle_wait_multiple: Duplication is ok for WaitAny, exception for WaitAll.
Fixes #9089

* Duplicate detection in mono_win32_wait_for_multiple_objects_ex, like mono_w32handle_wait_multiple.

* Move wait duplicate tests from mono/tests to mcs/class/corlib/Test/System.Threading/WaitHandleTest.cs.

Run them with e.g.:

`PATH="/s/mono2/runtime/_tmpinst/bin:/Users/jay/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/share/dotnet:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin:/Users/jay/bin" MONO_REGISTRY_PATH="/Users/jay/.mono/registry" MONO_TESTS_IN_PROGRESS="yes" DBG_RUNTIME_ARGS="" MONO_PATH="./../../class/lib/net_4_x-macos/:./../../class/lib/net_4_x-macos//tests:./../../../external/xunit-binaries:.:$MONO_PATH" /s/mono2/runtime/mono-wrapper --debug    ./../../class/lib/net_4_x-macos/nunit-lite-console.exe  ./../../class/lib/net_4_x/tests/net_4_x_corlib_test.dll    -exclude=NotOnMac,MacNotWorking,NotWorking,CAS  -format:nunit2 -result:TestResult-net_4_x.xml -test:MonoTests.System.Threading.WaitHandleTest.DuplicateWaitAll`

`PATH="/s/mono2/runtime/_tmpinst/bin:/Users/jay/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/share/dotnet:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin:/Users/jay/bin" MONO_REGISTRY_PATH="/Users/jay/.mono/registry" MONO_TESTS_IN_PROGRESS="yes" DBG_RUNTIME_ARGS="" MONO_PATH="./../../class/lib/net_4_x-macos/:./../../class/lib/net_4_x-macos//tests:./../../../external/xunit-binaries:.:$MONO_PATH" /s/mono2/runtime/mono-wrapper --debug    ./../../class/lib/net_4_x-macos/nunit-lite-console.exe  ./../../class/lib/net_4_x/tests/net_4_x_corlib_test.dll    -exclude=NotOnMac,MacNotWorking,NotWorking,CAS  -format:nunit2 -result:TestResult-net_4_x.xml -test:MonoTests.System.Threading.WaitHandleTest.DuplicateWaitAny`

Find the full names with:

`PATH="/s/mono2/runtime/_tmpinst/bin:/Users/jay/.cargo/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/Applications/VMware Fusion.app/Contents/Public:/usr/local/share/dotnet:/opt/X11/bin:/Library/Frameworks/Mono.framework/Versions/Current/Commands:/Applications/Xamarin Workbooks.app/Contents/SharedSupport/path-bin:/Users/jay/bin" MONO_REGISTRY_PATH="/Users/jay/.mono/registry" MONO_TESTS_IN_PROGRESS="yes" DBG_RUNTIME_ARGS="" MONO_PATH="./../../class/lib/net_4_x-macos/:./../../class/lib/net_4_x-macos//tests:./../../../external/xunit-binaries:.:$MONO_PATH" /s/mono2/runtime/mono-wrapper --debug    ./../../class/lib/net_4_x-macos/nunit-lite-console.exe  ./../../class/lib/net_4_x/tests/net_4_x_corlib_test.dll    -exclude=NotOnMac,MacNotWorking,NotWorking,CAS  -format:nunit2 -result:TestResult-net_4_x.xml -explore`

and look at the resulting .xml file.

I ran them w/ and w/o the fix, verify they both failed w/o and passed w/.
(w/o the fix was a slight hack of the fix)

* Move null checks so other uses can still null dereference.

* Short circuit duplicate search, correct either way.

* Fix windows build -- missing include.

* Add MonoError to mono_win32_wait_for_multiple_objects_ex, probably did this earlier but lost it somewhere in git.

* Add missing include.

* Follow shorter convention of rest of directory.

* Make the code slightly more complicated per PR.

* PR: Split into small used-once functions.

* cleanup

* add static

* PR: sizeof (array [0]) vs. sizeof (type)
@marek-safar marek-safar moved this from Done to Archived in Bugs Week Sep 24, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Bugs Week
Archived
3 participants
You can’t perform that action at this time.