Thanks to visit codestin.com
Credit goes to github.com

Skip to content

New erl_files (-hrl +beam) rule: {elvis_style, receive_with_timeout} #426

@paulo-ferraz-oliveira

Description

@paulo-ferraz-oliveira

Name

receive_with_timeout

Brief Description

All receive expressions should be accompanied by an after expressions.

Problematic code

receive
    onhook ->
        disconnect(),
        idle();
    {connect, B} ->
        B ! {busy, self()},
        wait_for_onhook()
end

Correct code

receive
    onhook ->
        disconnect(),
        idle();
    {connect, B} ->
        B ! {busy, self()},
        wait_for_onhook()
after
    60_000 ->
        exit(nothing_received)
end

Rationale

A receive block without a timeout will wait indefinitely if no matching message arrives; by making your timeout explicit you:

  • avoid hanging processes
  • improve testability (deterministic behaviour under test failure conditions)
  • ease debug and recovery
  • can implement retry and self-healing
  • potentially avoid denial-of-service scenarios where waits are exploited

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions