Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cluster) do not inadvertently log error messages #3002

Merged
merged 1 commit into from
Nov 2, 2017

Conversation

thibaultcha
Copy link
Member

The post_local API of the worker-events library can return false, nil when polling is skipped because we are posting from an event
handler, effectively nullifying the purpose of the first return value of
post_local.

My suggestion to lua-resty-worker-events would be to replace the
following line in post_local:

return _M.poll()

with a wrapper:

local ok, err = _M.poll()
if err then
    return nil, err
end

return true -- the event *was* posted

In the meantime, this commit changes the return values check to rely on
err ~= nil, thus avoiding such inadvertent error messages to show up.

Fix #2872

The `post_local` API of the worker-events library can return `false,
nil` when polling is skipped because we are posting from an event
handler, effectively nullifying the purpose of the first return value of
`post_local`.

My suggestion to lua-resty-worker-events would be to replace the
following line in `post_local`:

    return _M.poll()

with a wrapper:

    local ok, err = _M.poll()
    if err then
        return nil, err
    end

    return true -- the event *was* posted

In the meantime, this commit changes the return values check to rely on
`err ~= nil`, thus avoiding such inadvertent error messages to show up.

Fix #2872
Copy link
Member

@Tieske Tieske left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think for code readability it would be better to replace

if not ok then

with an explicit nil check:

if ok == nil then   -- `false` means it is successfully posted, but not yet dealt with.

also because you do not have to rely on the second return value.

@thibaultcha
Copy link
Member Author

I think the level of readability is about the same one way or the other. It is a common paradigm in our codebase to check for errors with the second return value already (unfortunately). I think that ideally, this should be updated in lua-resty-worker-events, because we are not calling poll() here, but post_event. As a user of this API, I wish that the return value tells me whether or not the event was posted, and I do not wish to have it superseded by internal-specifics.

@Tieske
Copy link
Member

Tieske commented Nov 2, 2017

btw, when implementing this:

local ok, err = _M.poll()
if err then
    return nil, err
end

return true -- the event *was* posted

You would loose the distinction between posted+handled and posted+unhandled. This is an important distinction.

(this discussion should probably be done in the worker-events repo)

@thibaultcha
Copy link
Member Author

thibaultcha commented Nov 2, 2017

Yes, I know. I would disagree that this distinction is important to make though, as highlighted here:

As a user of this API, I wish that the return value tells me whether or not the event was posted, and I do not wish to have it superseded by internal-specifics.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants