Running out of memory in custom session handler's `write` function causes "Cannot call session save handler in a recursive manner"
Chưa có ai nhận issue này.
- Ngôn ngữ chính
- C
- Star
- 40.4k
- Fork
- 8.2k
- Merge trung bình
- 2 ngày 15 giờ
- Pull request đã merge (30 ngày)
- 103
Mô tả
Description
The following code:
<?php
ini_set('memory_limit', '16M');
class TestSessionHandler implements SessionHandlerInterface
{
public function close(): bool
{
error_log("Close");
return true;
}
public function destroy(string $id): bool
{
error_log("Destroy");
return true;
}
public function gc(int $max_lifetime): int|false
{
error_log("GC");
return 0;
}
public function open(string $path, string $name): bool
{
error_log("Open");
return true;
}
public function read(string $id): string|false
{
error_log("Read");
return 'a|i:1234;';
}
public function write($id, $data): bool
{
error_log("About to run out of memory");
var_dump(strlen(str_repeat('0', 16777216)));
error_log("Wrote session");
return true;
}
}
session_set_save_handler(new TestSessionHandler());
session_start();
error_log("End of code");
Resulted in this output:
Open
Read
End of code
About to run out of memory
PHP Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 16777248 bytes) in /Users/ssigwart/Downloads/sessionsTest.php on line 35
Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 16777248 bytes) in /Users/ssigwart/Downloads/sessionsTest.php on line 35
PHP Warning: PHP Request Shutdown: Cannot call session save handler in a recursive manner in Unknown on line 0
Warning: PHP Request Shutdown: Cannot call session save handler in a recursive manner in Unknown on line 0
PHP Warning: PHP Request Shutdown: Failed to write session data using user defined save handler. (session.save_path: /usr/local/share/phpsess, handler: TestSessionHandler::updateTimestamp) in Unknown on line 0
Warning: PHP Request Shutdown: Failed to write session data using user defined save handler. (session.save_path: /usr/local/share/phpsess, handler: TestSessionHandler::updateTimestamp) in Unknown on line 0
Close
But I expected this output instead:
Open
Read
End of code
About to run out of memory
PHP Fatal error: Allowed memory size of 16777216 bytes exhausted (tried to allocate 16777248 bytes) in /Users/ssigwart/Downloads/sessionsTest.php on line 35
I'd expect the fatal error, but not the recursive session call.
The above simulates the error using a large string, but this happens when a session is large and the custom error handler needs to allocate some more data to write the data.
PHP Version
PHP 8.1.29, PHP 8.3.10
Operating System
No response
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu bằng cách chạy bản tái hiện PHP trong issue với PHP 8.1.29 hoặc 8.3.10 và so sánh đầu ra shutdown với lỗi fatal dự kiến. Theo dõi lệnh gọi write của session handler tùy chỉnh trong khi request shutdown; hoàn tất khi lỗi fatal out-of-memory vẫn còn mà không có cảnh báo gọi session đệ quy và cảnh báo ghi thất bại.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- php
- Lĩnh vực
- backend
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Khá rõ ràng
- Mức phù hợp với người mới
- 35/100