-
Notifications
You must be signed in to change notification settings - Fork 78
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #621 from bugsnag/handle-ooms
Allow Bugsnag\Handler to handle OOMs
- Loading branch information
Showing
12 changed files
with
294 additions
and
0 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
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
30 changes: 30 additions & 0 deletions
30
tests/phpt/handler_should_increase_memory_limit_by_configured_amount_on_oom.phpt
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,30 @@ | ||
--TEST-- | ||
Bugsnag\Handler should increase the memory limit by the configured amount when an OOM happens | ||
--FILE-- | ||
<?php | ||
$client = require __DIR__ . '/_prelude.php'; | ||
$client->setMemoryLimitIncrease(1024 * 1024 * 10); | ||
|
||
ini_set('memory_limit', '2M'); | ||
var_dump(ini_get('memory_limit')); | ||
|
||
$client->registerCallback(function () { | ||
var_dump(ini_get('memory_limit')); | ||
}); | ||
|
||
Bugsnag\Handler::register($client); | ||
|
||
$a = str_repeat('a', 2147483647); | ||
|
||
echo "No OOM!\n"; | ||
?> | ||
--EXPECTF-- | ||
string(2) "2M" | ||
|
||
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line 14 | ||
string(8) "12582912" | ||
Guzzle request made (1 event)! | ||
* Method: 'POST' | ||
* URI: 'http://localhost/notify' | ||
* Events: | ||
- Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) |
32 changes: 32 additions & 0 deletions
32
...phpt/handler_should_not_increase_memory_limit_when_memory_limit_increase_is_disabled.phpt
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,32 @@ | ||
--TEST-- | ||
Bugsnag\Handler should not increase the memory limit when memoryLimitIncrease is disabled | ||
--FILE-- | ||
<?php | ||
$client = require __DIR__ . '/_prelude.php'; | ||
$client->setMemoryLimitIncrease(null); | ||
|
||
ini_set('memory_limit', '5M'); | ||
var_dump(ini_get('memory_limit')); | ||
|
||
$client->registerCallback(function () { | ||
// This should be the same as the first var_dump, because we should not have | ||
// increase the memory limit | ||
var_dump(ini_get('memory_limit')); | ||
}); | ||
|
||
Bugsnag\Handler::register($client); | ||
|
||
$a = str_repeat('a', 2147483647); | ||
|
||
echo "No OOM!\n"; | ||
?> | ||
--EXPECTF-- | ||
string(2) "5M" | ||
|
||
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line 16 | ||
string(2) "5M" | ||
Guzzle request made (1 event)! | ||
* Method: 'POST' | ||
* URI: 'http://localhost/notify' | ||
* Events: | ||
- Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) |
21 changes: 21 additions & 0 deletions
21
tests/phpt/handler_should_report_oom_from_large_allocation.phpt
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,21 @@ | ||
--TEST-- | ||
Bugsnag\Handler should report OOMs triggered by single large allocations | ||
--FILE-- | ||
<?php | ||
$client = require __DIR__ . '/_prelude.php'; | ||
|
||
ini_set('memory_limit', '5M'); | ||
|
||
Bugsnag\Handler::register($client); | ||
|
||
$a = str_repeat('a', 2147483647); | ||
|
||
echo "No OOM!\n"; | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line 8 | ||
Guzzle request made (1 event)! | ||
* Method: 'POST' | ||
* URI: 'http://localhost/notify' | ||
* Events: | ||
- Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) |
35 changes: 35 additions & 0 deletions
35
tests/phpt/handler_should_report_oom_from_small_allocations.phpt
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,35 @@ | ||
--TEST-- | ||
Bugsnag\Handler should report OOMs triggered by many small allocations | ||
--FILE-- | ||
<?php | ||
|
||
$client = require __DIR__ . '/_prelude.php'; | ||
|
||
$handler = Bugsnag\Handler::register($client); | ||
|
||
ini_set('memory_limit', '5M'); | ||
|
||
$i = 0; | ||
|
||
gc_disable(); | ||
|
||
while ($i++ < 12345678) { | ||
$a = new stdClass; | ||
$a->b = $a; | ||
} | ||
|
||
echo "No OOM!\n"; | ||
?> | ||
--SKIPIF-- | ||
<?php | ||
if (PHP_MAJOR_VERSION < 7) { | ||
echo "SKIP - PHP 5 does not run OOM in this test"; | ||
} | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line %d | ||
Guzzle request made (1 event)! | ||
* Method: 'POST' | ||
* URI: 'http://localhost/notify' | ||
* Events: | ||
- Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) |
34 changes: 34 additions & 0 deletions
34
tests/phpt/php5/handler_should_report_oom_from_small_allocations.phpt
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,34 @@ | ||
--TEST-- | ||
Bugsnag\Handler should report OOMs triggered by many small allocations | ||
--FILE-- | ||
<?php | ||
|
||
$client = require __DIR__ . '/../_prelude.php'; | ||
|
||
$handler = Bugsnag\Handler::register($client); | ||
|
||
ini_set('memory_limit', '5M'); | ||
|
||
$size = 1024 * 256; | ||
|
||
$array = new SplFixedArray($size); | ||
|
||
for ($i = 0; $i < $size; ++$i) { | ||
$array[$i] = str_repeat('a', 32); | ||
} | ||
|
||
echo "No OOM!\n"; | ||
?> | ||
--SKIPIF-- | ||
<?php | ||
if (PHP_MAJOR_VERSION !== 5) { | ||
echo 'SKIP — this test does not run on PHP 7 & 8'; | ||
} | ||
?> | ||
--EXPECTF-- | ||
Fatal error: Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) in %s on line 14 | ||
Guzzle request made (1 event)! | ||
* Method: 'POST' | ||
* URI: 'http://localhost/notify' | ||
* Events: | ||
- Allowed memory size of %d bytes exhausted (tried to allocate %d bytes) |