[BUG] Infinite loop while reading a stream
pmartelletti opened this issue · 3 comments
Imagine I have a stream called 'A', and that I have 1 event for that stream. When I try consume all the events for this stream, the first event is read correctly with:
if ($feed->hasLink(LinkRelation::LAST())) {
$feed = $this->eventStore->navigateStreamFeed($feed, LinkRelation::LAST());
} else {
$feed = $this->eventStore->navigateStreamFeed($feed, LinkRelation::FIRST());
}
Then, when fetching next feed, I expect it to be NULL. However, I'm getting an instance of StreamFeed. If I do a while, like suggested in the readme, I'll get an infinite loop, because the eventStore->navigateStreamFeed
(using previous) will always return always this stream feed:
{
"title": "Event stream '5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef'",
"id": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef",
"updated": "0001-01-01T03:00:00Z",
"streamId": "5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef",
"author": {
"name": "EventStore"
},
"headOfStream": false,
"links": [
{
"uri": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef",
"relation": "self"
},
{
"uri": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef/head/backward/20",
"relation": "first"
},
{
"uri": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef/0/forward/20",
"relation": "last"
},
{
"uri": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef/0/backward/20",
"relation": "next"
},
{
"uri": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef/1/forward/20",
"relation": "previous"
},
{
"uri": "http://localhost:2113/streams/5fdb4de2-093a-4bf5-b0f0-32cde3c3cdef/metadata",
"relation": "metadata"
}
],
"entries": []
}
I've checked why is that, and the reason is that the method navigateFeed
will only return null when there is no link for previous, but this feed always has.
@dbellettini Any ideas of we could check on the length of "entries" to return null instead? or at least check in both properties?
Thanks,
I will check in the weekend
I just updated the wiki, does it solve the issue?
@dbellettini thanks! I'll try it on monday, and will let you know about it!