forked from tarantool/tarantool
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
lua/fiber: do not raise on printing a dead fiber
An attempt to print a dead fiber raised a fatal error, which is quite unexpected. This patch updates __tostring metamethod of fiber_object so that it pushes the "fiber: <fid> (dead)" string instead of the error. The __serialize metamethod is patched similarly. Closes tarantool#4265 NO_DOC=bugfix
- Loading branch information
Showing
5 changed files
with
69 additions
and
15 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
changelogs/unreleased/gh-4265-printing-a-finished-fiber-stops-the-program.md
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,3 @@ | ||
## bugfix/core | ||
|
||
* An error is no longer raised on an attempt to print a dead fiber (gh-4265). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
local fiber = require('fiber') | ||
local t = require('luatest') | ||
local g = t.group('fiber') | ||
|
||
-- Test __serialize metamethod of the fiber. | ||
g.test_serialize = function() | ||
local f = fiber.new(function() end) | ||
local fid = f:id() | ||
f:name('test fiber') | ||
|
||
-- Serialize a ready fiber. | ||
t.assert_equals(f:__serialize(), | ||
{ id = fid, name = 'test fiber', status = 'suspended' }) | ||
|
||
-- gh-4265: Serializing a finished fiber should not raise an error. | ||
fiber.yield() | ||
t.assert_equals(f:__serialize(), { id = fid, status = 'dead' }) | ||
|
||
-- Serialize a running fiber. | ||
t.assert_equals(fiber.self():__serialize(), | ||
{ id = fiber.self():id(), | ||
name = 'luatest', | ||
status = 'running' }) | ||
end | ||
|
||
-- Test __tostring metamethod of the fiber. | ||
g.test_tostring = function() | ||
local f = fiber.new(function() end) | ||
local fid = f:id() | ||
|
||
t.assert_equals(tostring(f), "fiber: " .. fid) | ||
|
||
-- gh-4265: Printing a finished fiber should not raise an error. | ||
fiber.yield() | ||
t.assert_equals(tostring(f), "fiber: " .. fid .. " (dead)") | ||
end |
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