galenwarren commented on a change in pull request #303:
URL: https://github.com/apache/flink-statefun/pull/303#discussion_r813131613
##########
File path: statefun-sdk-go/v3/pkg/statefun/context.go
##########
@@ -76,6 +81,12 @@ func (s *statefunContext) Storage() AddressScopedStorage {
return s.storage
}
+func (s *statefunContext) WithContext(ctx context.Context) Context {
+ newContext := *s
+ newContext.Context = ctx
+ return &newContext
Review comment:
Unless I'm mistaken, the initial assignment operation:
```
newContext := *s
```
... will shallow copy all the fields from the existing `statefunContext` to
the new one, including the caller (a pointer), self (not a pointer), storage (a
pointer), address (a pointer), response (a pointer), and the mutex (a pointer).
(EDIT: And the context (interface) too, but that is overwritten in the next
line.)
This means that both contexts will share the same mutex and response, which
is what we want, I think? The mutex is used to serialize access to fields in
the response, i.e.:
```
s.Lock()
s.response.OutgoingMessages = append(s.response.OutgoingMessages, invocation)
s.Unlock()
```
My read of the linked thread is that it describes how to copy a mutex when
it is directly embedded (i.e. not a pointer); in this case, we have the option
to make it a pointer and sidestep the problem. But please let me know if you
disagree. Thanks.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]