Skip to content

Commit 3229ede

Browse files
committed
Sync to TFS
1 parent c575472 commit 3229ede

File tree

3 files changed

+39
-18
lines changed

3 files changed

+39
-18
lines changed

Release/src/websockets/client/ws_winrt.cpp

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
* =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-
2626
****/
2727
#include "stdafx.h"
28+
#include <concrt.h>
2829

2930
#if WINAPI_FAMILY == WINAPI_FAMILY_APP
3031

@@ -115,16 +116,30 @@ class winrt_client : public _websocket_client_impl
115116
tce.set_exception(std::make_exception_ptr(websocket_exception(_XPLATSTR("Error occured during receive."))));
116117
}
117118
},
118-
[=]()
119+
[=]() // Close handler called upon receiving a close frame from the server.
119120
{
120-
close_pending_tasks_with_error();
121+
close_pending_tasks_with_error();
121122
m_close_tce.set();
123+
m_server_close_complete.set();
122124
});
123125
}
124126

125127
~winrt_client()
126128
{
127-
close_pending_tasks_with_error();
129+
// task_completion_event::set() returns false if it has already been set.
130+
// In that case, wait on the m_server_close_complete event for the tce::set() to complete.
131+
// The websocket client on close handler (upon receiving close frame from server) will
132+
// set this event.
133+
// If we have not received a close frame from the server, this set will be a no-op as the
134+
// websocket_client is anyways destructing.
135+
if (!m_close_tce.set())
136+
{
137+
m_server_close_complete.wait();
138+
}
139+
else
140+
{
141+
close_pending_tasks_with_error();
142+
}
128143
}
129144

130145
void close_pending_tasks_with_error()
@@ -298,6 +313,13 @@ class winrt_client : public _websocket_client_impl
298313
ReceiveContext ^ m_context;
299314

300315
pplx::task_completion_event<void> m_close_tce;
316+
// There is a bug in ppl task_completion_event. The task_completion_event::set() accesses some
317+
// internal data after signalling the event. The waiting thread might go ahead and start destroying the
318+
// websocket_client. Due to this race, set() can cause a crash.
319+
// To workaround this bug, maintain another event: m_server_close_complete. We will signal this when the m_close_tce.set() has
320+
// completed. The websocket_client destructor can wait on this event before proceeding.
321+
Concurrency::event m_server_close_complete;
322+
301323
// m_client_closed maintains the state of the client. It is set to true when:
302324
// 1. the client has not connected
303325
// 2. if it has received a close frame from the server.

Release/tests/Common/UnitTestpp/src/TestList.h

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
/***
22
* This file is based on or incorporates material from the UnitTest++ r30 open source project.
3-
* Microsoft is not the original author of this code but has modified it and is licensing the code under
4-
* the MIT License. Microsoft reserves all other rights not expressly granted under the MIT License,
5-
* whether by implication, estoppel or otherwise.
3+
* Microsoft is not the original author of this code but has modified it and is licensing the code under
4+
* the MIT License. Microsoft reserves all other rights not expressly granted under the MIT License,
5+
* whether by implication, estoppel or otherwise.
66
*
7-
* UnitTest++ r30
7+
* UnitTest++ r30
88
*
99
* Copyright (c) 2006 Noel Llopis and Charles Nicholson
1010
* Portions Copyright (c) Microsoft Corporation
@@ -13,19 +13,19 @@
1313
*
1414
* MIT License
1515
*
16-
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
17-
* and associated documentation files (the "Software"), to deal in the Software without restriction,
18-
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
19-
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
16+
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software
17+
* and associated documentation files (the "Software"), to deal in the Software without restriction,
18+
* including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense,
19+
* and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so,
2020
* subject to the following conditions:
2121
*
22-
* The above copyright notice and this permission notice shall be included in all copies or
22+
* The above copyright notice and this permission notice shall be included in all copies or
2323
* substantial portions of the Software.
2424
*
25-
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
26-
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
27-
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
28-
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
25+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
26+
* INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE
27+
* AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
28+
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
2929
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
3030
***/
3131

@@ -42,7 +42,6 @@ class TestList
4242
{
4343
public:
4444
UNITTEST_LINKAGE TestList();
45-
4645
UNITTEST_LINKAGE void Add(Test* test);
4746

4847
UNITTEST_LINKAGE Test* GetFirst() const;

Release/tests/Functional/http/listener/VS12/HttpListener120_test.vcxproj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@
7676
<PlatformToolset>v120</PlatformToolset>
7777
</PropertyGroup>
7878
<Import Project="$(VCTargetsPath)\Microsoft.Cpp.props" />
79-
<Import Project="..\..\..\..\..\..\..\Build\Release.Tests.Settings" />
79+
<Import Project="$([MSBuild]::GetDirectoryNameOfFileAbove($(MSBuildThisFileDirectory), build.root))\Build\Release.Tests.Settings" />
8080
<ImportGroup Label="ExtensionSettings">
8181
</ImportGroup>
8282
<ImportGroup Label="PropertySheets" Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">

0 commit comments

Comments
 (0)