Skip to content

Commit

Permalink
Fix random 0xC0000001 errors when querying for Connections (#1335)
Browse files Browse the repository at this point in the history
Fix random 0xC0000001 errors when querying for Connections (#1335)
  • Loading branch information
sylvainduchesne authored and giampaolo committed Sep 26, 2018
1 parent 7be5d9c commit 1d7516c
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
2 changes: 1 addition & 1 deletion CREDITS
Original file line number Diff line number Diff line change
Expand Up @@ -548,7 +548,7 @@ N: Alex Manuskin
W: https://github.com/amanusk
I: 1284

N: sylvainduchesne
N: Sylvain Duchesne
W: https://github.com/sylvainduchesne
I: 1294

Expand Down
4 changes: 3 additions & 1 deletion HISTORY.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ XXXX-XX-XX

- 1332_: psutil debug messages are erroneously printed all the time. (patch by
yanok)

- 1294_: [Windows] psutil.Process().connections() may sometimes fail with
intermittent 0xC0000001. (patch by Sylvain Duchesne)

5.4.7
=====

Expand Down
14 changes: 6 additions & 8 deletions psutil/_psutil_windows.c
Original file line number Diff line number Diff line change
Expand Up @@ -1530,15 +1530,14 @@ static DWORD __GetExtendedTcpTable(_GetExtendedTcpTable call,
// that the size of the table increases between the moment where we
// query the size and the moment where we query the data. Therefore, it's
// important to call this in a loop to retry if that happens.
//
// Also, since we may loop a theoretically unbounded number of times here,
// release the GIL while we're doing this.
// See https://github.com/giampaolo/psutil/pull/1335 concerning 0xC0000001 error
// and https://github.com/giampaolo/psutil/issues/1294
DWORD error = ERROR_INSUFFICIENT_BUFFER;
*size = 0;
*data = NULL;
error = call(NULL, size, FALSE, address_family,
TCP_TABLE_OWNER_PID_ALL, 0);
while (error == ERROR_INSUFFICIENT_BUFFER)
while (error == ERROR_INSUFFICIENT_BUFFER || error == 0xC0000001)
{
*data = malloc(*size);
if (*data == NULL) {
Expand Down Expand Up @@ -1569,15 +1568,14 @@ static DWORD __GetExtendedUdpTable(_GetExtendedUdpTable call,
// that the size of the table increases between the moment where we
// query the size and the moment where we query the data. Therefore, it's
// important to call this in a loop to retry if that happens.
//
// Also, since we may loop a theoretically unbounded number of times here,
// release the GIL while we're doing this.
// See https://github.com/giampaolo/psutil/pull/1335 concerning 0xC0000001 error
// and https://github.com/giampaolo/psutil/issues/1294
DWORD error = ERROR_INSUFFICIENT_BUFFER;
*size = 0;
*data = NULL;
error = call(NULL, size, FALSE, address_family,
UDP_TABLE_OWNER_PID, 0);
while (error == ERROR_INSUFFICIENT_BUFFER)
while (error == ERROR_INSUFFICIENT_BUFFER || error == 0xC0000001)
{
*data = malloc(*size);
if (*data == NULL) {
Expand Down

0 comments on commit 1d7516c

Please sign in to comment.