Skip Menu |

Preferred bug tracker

Please visit the preferred bug tracker to report your issue.

This queue is for tickets about the Web-Machine CPAN distribution.

Report information
The Basics
Id: 101203
Status: resolved
Priority: 0/
Queue: Web-Machine

People
Owner: Nobody in particular
Requestors: SMITHFARM [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: (no value)
Broken in: (no value)
Fixed in: (no value)



Subject: Please call allowed_methods method only once
In Web::Machine::FSM::States there is this code: $STATE_DESC{'b10'} = 'method_allowed'; sub b10 { my ($resource, $request, $response) = @_; my $method = $request->method; return \&b9 if grep { $method eq $_ } @{ $resource->allowed_methods }; $response->header('Allow' => join ", " => @{ $resource->allowed_methods } ); return \405; } which has the effect of calling my 'allowed_methods' method twice, which is confusing at best and at worst might introduce a race condition (?). Please consider calling it only once by doing something like this: $STATE_DESC{'b10'} = 'method_allowed'; sub b10 { my ($resource, $request, $response) = @_; my $method = $request->method; my @allowed_methods = @{ $resource->allowed_methods }; return \&b9 if grep { $method eq $_ } @allowed_methods; $response->header('Allow' => join ", " => @allowed_methods ); return \405; } Thanks.
Subject: Re: [rt.cpan.org #101203] Please call allowed_methods method only once
Date: Tue, 30 Dec 2014 22:11:08 -0800
To: bug-Web-Machine [...] rt.cpan.org
From: Thomas Sibley <tsibley [...] cpan.org>
On 12/30/2014 02:17 AM, Nathan Cutler via RT wrote: Show quoted text
> which has the effect of calling my 'allowed_methods' method twice, > which is confusing at best and at worst might introduce a race condition > (?). Please consider calling it only once by doing something like this: > > $STATE_DESC{'b10'} = 'method_allowed'; > sub b10 { > my ($resource, $request, $response) = @_; > my $method = $request->method; > my @allowed_methods = @{ $resource->allowed_methods }; > return \&b9 if grep { $method eq $_ } @allowed_methods; > $response->header('Allow' => join ", " => @allowed_methods ); > return \405; > }
This seems reasonable. +1
Multiple calls to the same method are the norm, rather than the exception, in Web::Machine::FSM::States, so fixing just this one instance might not be deemed systemic. On the other hand, ensuring that no method gets called more than once might be a lot of work. To me, the FSM diagram seems to imply that the individual methods should get called only once. And the documentation does not warn me that my overlay implementations of these methods need to be idempotent. I am willing to hack on Web::Machine::FSM::States and submit a patch for this, if you guys agree it is a good thing to do.
Subject: Re: [rt.cpan.org #101203] allowed_methods is called twice per request, forcing method to be idempotent
Date: Thu, 1 Jan 2015 11:15:01 +0100
To: bug-Web-Machine [...] rt.cpan.org
From: Stevan Little <stevan.little [...] gmail.com>
Nathan, You are correct, the docs do not mention that these methods should be idempotent and this was likely an assumption we inherited from the Erlang implementation. I think that it should both; be documented (as a suggestion and not a hard rule, this *is* Perl after all) and we should do our best (when appropriate) to not incur the second method call (both for performance reasons and do-not-assume-things-are-idempotent reasons). If you are willing to hack on this, that would be great, please submit pull requests via https://github.com/stevan/webmachine-perl and we will be happy to review and integrate. - Stevan On Wed, Dec 31, 2014 at 1:01 PM, Nathan Cutler via RT < bug-Web-Machine@rt.cpan.org> wrote: Show quoted text
> Queue: Web-Machine > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=101203 > > > Multiple calls to the same method are the norm, rather than the exception, > in Web::Machine::FSM::States, so fixing just this one instance might not be > deemed systemic. On the other hand, ensuring that no method gets called > more than once might be a lot of work. > > To me, the FSM diagram seems to imply that the individual methods should > get called only once. And the documentation does not warn me that my > overlay implementations of these methods need to be idempotent. > > I am willing to hack on Web::Machine::FSM::States and submit a patch for > this, if you guys agree it is a good thing to do. >
Show quoted text
> If you are willing to hack on this, that would be great, please submit > pull > requests via https://github.com/stevan/webmachine-perl and we will be > happy > to review and integrate.
Thanks, Stevan! The first pull request is ready: https://github.com/stevan/webmachine-perl/pull/31 Nathan