On the Context interface, Caller is defined like this:

// Caller is the caller function instance's Address, if applicable. This is
nil
// if the message was sent to this function via an ingress.
Caller() *Address

... so, in the event a function is invoked from an ingress, as opposed to
from another function, the returned value should be nil.

However, it seems that the statefunContext.caller property -- the value of
which is returned by Caller() -- is always set to a non-nil value when the
context is constructed. From handler.go:

sContext := statefunContext{
Mutex:    new(sync.Mutex),
self:     self,
storage:  storage,
response: response,
}

var cancel context.CancelFunc
sContext.Context, cancel = context.WithCancel(ctx)

* var caller Address*
* if invocation.Caller != nil {*
* caller = addressFromInternal(invocation.Caller)*
* }*
* sContext.caller = &caller*

So, even when there is no caller associated with the invocation, the caller
field is set to a non-nil pointer, and the referenced Address has
FunctionType=nil and Id="", which is then returned by Context.Caller().

Should the bolded code instead be the following, to only assign
sContext.caller when the invocation has an associated caller?

if invocation.Caller != nil {
caller := addressFromInternal(invocation.Caller)
sContext.caller = &caller
}

I'd be happy to submit a fix if needed ... thanks.

Reply via email to