Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Returning the pointer to the channel is having race issues #24

Open
0cv opened this issue Jul 20, 2019 · 1 comment
Open

Returning the pointer to the channel is having race issues #24

0cv opened this issue Jul 20, 2019 · 1 comment

Comments

@0cv
Copy link
Contributor

0cv commented Jul 20, 2019

Prerequisite:
1- Subscribe to the orders, e.g. with SubscribeUserOrdersKind

Reproduction steps:
1- create 2 or more limits order in an open position (so that an array is returned and not a single value)
2- click on "Cancel All"

An array of cancelled orders is returned in a websocket by Deribit. This code https://github.com/adampointer/go-deribit/blob/master/v3/rpc_subscriptions.go#L759 handles the array and sends each element to the channel here https://github.com/adampointer/go-deribit/blob/master/v3/rpc_subscriptions.go#L765. For some reasons, which I'm not aware of due to my limited knowledge in Go, the channel receives the same pointer address for the first two elements. The third element (if there were 3 open orders) is another order.

Solution found: I'm not sure it's ideal, I also don't know why a pointer was returned instead of the value (again my Go knowledge are a bit limited) but my solution was simply to not return a pointer, just its value, it seems to do the trick. But whether there are other consequences?..

@adampointer
Copy link
Owner

Hi.

This is an interesting one. I have done a little research and it looks like passing pointers on channels is slower as we use the heap rather than the stack. So maybe that is introducing the race. I always use pointers by default as I like to avoid unnecessary copying. However I guess my computer science is not that great. If your solution works then submit a PR for it.

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

No branches or pull requests

2 participants