This repository has been archived by the owner on Jun 18, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 132
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is a response to a memory leak that was witnessed in our stress testing. Below is a list of reading that should illuminate this change: http://create.tpsitulsa.com/wiki/V8/Persistent_Handles https://developers.google.com/v8/embed#handles Basically, we were using a persistent handle to hold a reference to ourselves in the Connection class. This prevented the Collection class from being collected properly. The solution is to use a weak persistent handle. The node::ObjectWrap class, which the Connection class inherits from, is a WeakHandle and manages the lifetime properly, calling the destructor (provided it is virtual) of our instance when it is being collected. A destructor was added to the Connection class that closes the ODBC connection if necessary. Since there are now two paths into closing a connection, it is possible for a race condition to arise. A critical section has been put around the code that disconnects from SQL Server to prevent this. For now this critical section code is Windows specific. It will be rewritten as cross platform at a later time. Also, we were potentially leaking a persistent handle to the OdbcConnection class in the OpenOperation class, meaning that the OpenConnection class would never be collected. To fix this, we call the Dispose member function of the persistent handle to notify V8 that we no longer need the pointer. Microsoft Internal Review Id: jaykint-559c37537fb54de28ea1481d9bdf55cb
- Loading branch information
Showing
9 changed files
with
153 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
//--------------------------------------------------------------------------------------------------------------------------------- | ||
// File: CriticalSection.h | ||
// Contents: Wrapper for a critical section that handles scope | ||
// | ||
// Copyright Microsoft Corporation and contributors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// | ||
// You may obtain a copy of the License at: | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
//--------------------------------------------------------------------------------------------------------------------------------- | ||
|
||
namespace mssql { | ||
|
||
class CriticalSection { | ||
|
||
public: | ||
|
||
CriticalSection() | ||
{ | ||
InitializeCriticalSection( &handle_ ); | ||
} | ||
|
||
~CriticalSection() | ||
{ | ||
DeleteCriticalSection( &handle_ ); | ||
} | ||
|
||
void lock( void ) | ||
{ | ||
EnterCriticalSection( &handle_ ); | ||
} | ||
|
||
void unlock( void ) | ||
{ | ||
LeaveCriticalSection( &handle_ ); | ||
} | ||
|
||
private: | ||
|
||
CRITICAL_SECTION handle_; | ||
}; | ||
|
||
class ScopedCriticalSectionLock { | ||
|
||
public: | ||
|
||
ScopedCriticalSectionLock( CriticalSection& cs ) : | ||
criticalSection_( cs ) | ||
{ | ||
criticalSection_.lock(); | ||
} | ||
|
||
~ScopedCriticalSectionLock( void ) | ||
{ | ||
criticalSection_.unlock(); | ||
} | ||
|
||
private: | ||
|
||
CriticalSection& criticalSection_; | ||
}; | ||
|
||
} // mssql |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -64,8 +64,6 @@ namespace mssql | |
|
||
callback->Call(Undefined().As<Object>(), argc, args); | ||
} | ||
|
||
callback.Dispose(); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters