- Merge request !4Issue #3228797: "Call to a member function eof() on null" can be returned in certain circumstances β (Open) created by GuyPaddock
- last update
12 months ago 30 pass
We're not 100% sure why this happens, but every so often when our site is requesting data from another system through a remote stream wrapper over HTTP, the site will error out with the error Error: Call to a member function eof() on null in Drupal\remote_stream_wrapper\StreamWrapper\HttpStreamWrapper->stream_eof() (line 116)
.
Looking through the code, I can see only two situations that would cause $this->stream
to be null
for an open stream:
stat()
was called, so HttpStreamWrapper::request()
did not populate the response because it only did a HEAD
request;I think situation 2 is the more likely case since I can't see any way for the stream resource to be open for an fstat()
call.
Not 100% sure on repro, but I think the situation is:
stream_eof()
at the top of the loop:$wrapper = new \Drupal\remote_stream_wrapper\StreamWrapper\HttpStreamWrapper(); $wrapper->setUri('http://path/to/badserver'); if ($wrapper->stream_open()) { while (!$wrapper->stream_eof()) { print $wrapper->stream_read() . "\n"; } }
If the response body is empty in HttpStreamWrapper::request()
, populate the stream with an empty array-based stream.
Needs review
1.0
Code
Not all content is available!
It's likely this issue predates Contrib.social: some issue and comment data are missing.