Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Locking... #8

Closed
ast opened this issue Mar 27, 2019 · 10 comments
Closed

Locking... #8

ast opened this issue Mar 27, 2019 · 10 comments

Comments

@ast
Copy link

ast commented Mar 27, 2019

I was wondering if node.Send() was safe to call from a worker go routine, so I was digging around in the code and noticed that some structures node.connections, for example, was protected by a mutex for writing, but not for reading. This is not sufficient (unless I'm missing something?)

node.connections could ideally be protected by a RWMutex (https://golang.org/pkg/sync/#RWMutex) that can be held by many readers but only one writer...

Let me know if you are interested in a pull request, or am I missing something clever?

Fantastic project!! After struggling with writing a stdin/stdout port with a lot of buffering issues I'm so happy I found this!

Not protected:
https://github.com/halturin/ergonode/blob/d13e6eebb13d3f1589a62e789ce4a947fc24ed34/ergonode.go#L442

Protected:
https://github.com/halturin/ergonode/blob/c08e4a55356eb58cbe82a07a1d020153c550b003/ergonode.go#L373

@halturin
Copy link
Collaborator

halturin commented Apr 1, 2019

Hi, sorry for delay with answer.

I'm happy to hear that this project is useful and can be a painkiller for you :). I will try to look it deeper a bit later, but you are welcome to make PR

@ast
Copy link
Author

ast commented Apr 3, 2019

Hi, no problem!

I will look into it and see if I can put together a pull request! So far it's working really great. Probably the best way to integrate golang libraries with erlang.

Maybe now with the introduction of go modules it can also be built as part of a rebar3 application.

@ciyrus
Copy link

ciyrus commented Jun 5, 2019

Hi a small question.

how to convert the int parameters in gen server call
sample call
gen_server:call({examplegs,'test@localhost'}, {getZrange,{num_list_11111111,2}}).

i can get getZrange and num_list_11111111 but {2...) gives error

if i change 2 in to a string then its working
gen_server:call({examplegs,'test@localhost'}, {getZrange,{num_list_11111111,'2'}}).

Call recovered: &runtime.TypeAssertionError{_interface:(*runtime._type)(0x8be3a0), concrete:(*runtime._type)(0x88f380), asserted:(*runtime._type)(0x88e880), missingMethod:""}

please help me on this

@halturin
Copy link
Collaborator

halturin commented Jun 5, 2019

@ciyrus could you please show me your implementation of genserver

@ciyrus
Copy link

ciyrus commented Jun 5, 2019

@halturin

Thank You for the reply
Im new to both Go and Erlang. so pls ignore if any mistakes are there

just executing below in Erlang shell
gen_server:call({examplegs,'test@localhost'}, {getZrange}).

in go implementation i'm getting the parameters like below
c := req[0].(etf.Atom)
println(c)

input 1
gen_server:call({examplegs,'test@localhost'}, {getZrange}).

output 1 in go

getZrange

input 2 (changed getZrange to an integer)
gen_server:call({examplegs,'test@localhost'}, {100}).

output 2 in go
Call recovered: &runtime.TypeAssertionError{_interface:(*runtime._type)(0x8be3a0), concrete:(*runtime._type)(0x88f380), asserted:(*runtime._type)(0x88e880), missingMethod:""}

@halturin
Copy link
Collaborator

halturin commented Jun 5, 2019

The reason of this behavior due to this line

c := req[0].(etf.Atom)

It's expected an atom, not an integer.

@ciyrus
Copy link

ciyrus commented Jun 6, 2019

Can u please guide how to convert it to integer.
Because I tried following and got the same error
strconv.Atoi
strconv.ParseInt

@halturin
Copy link
Collaborator

halturin commented Jun 6, 2019

Please, have a look this example

https://github.com/halturin/ergonode/blob/master/examples/gonode.go

Especially line 48.

@ciyrus
Copy link

ciyrus commented Jun 7, 2019

@halturin

Thanks a lot. found it. need to check the type first... that's what i missed

Once again Thanks a lot

@halturin
Copy link
Collaborator

i've just merged a bunch of updates, so its not valid anymore

halturin added a commit that referenced this issue Apr 6, 2021
# This is the 1st commit message:

osdep

# This is the commit message #2:

Fix Windows support (#30)

* Fix Windows support

* Updates for the tests related to the timing conditions due to specifics of the testing environment
# This is the commit message #3:

Update README.md
# This is the commit message #4:

sync

# This is the commit message #5:

sync

# This is the commit message #6:

fix TermIntoStruct. new TermMapIntoStruct

# This is the commit message #7:

sync

# This is the commit message #8:

sync

# This is the commit message #9:

sync

# This is the commit message #10:

sync

# This is the commit message #11:

sync

# This is the commit message #12:

sync

# This is the commit message #13:

sync

# This is the commit message #14:

sync

# This is the commit message #15:

sync

# This is the commit message #16:

sync

# This is the commit message #17:

sync

# This is the commit message #18:

sync

# This is the commit message #19:

sync

# This is the commit message #20:

sync

# This is the commit message #21:

sync

# This is the commit message #22:

sync

# This is the commit message #23:

sync

# This is the commit message #24:

sync

# This is the commit message #25:

sync

# This is the commit message #26:

sync

# This is the commit message #27:

sync

# This is the commit message #28:

sync

# This is the commit message #29:

sync

# This is the commit message #30:

sync

# This is the commit message #31:

sync

# This is the commit message #32:

sync

# This is the commit message #33:

sync

# This is the commit message #34:

sync

# This is the commit message #35:

sync

# This is the commit message #36:

sync

# This is the commit message #37:

sync

# This is the commit message #38:

sync

# This is the commit message #39:

sync

# This is the commit message #40:

sync

# This is the commit message #41:

sync

# This is the commit message #42:

sync

# This is the commit message #43:

sync

# This is the commit message #44:

sync

# This is the commit message #45:

sync

# This is the commit message #46:

sync

# This is the commit message #47:

sync

# This is the commit message #48:

sync

# This is the commit message #49:

sync

# This is the commit message #50:

sync

# This is the commit message #51:

sync

# This is the commit message #52:

sync

# This is the commit message #53:

sync

# This is the commit message #54:

sync

# This is the commit message #55:

sync

# This is the commit message #56:

sync

# This is the commit message #57:

sync

# This is the commit message #58:

sync

# This is the commit message #59:

sync

# This is the commit message #60:

sync

# This is the commit message #61:

sync

# This is the commit message #62:

sync

# This is the commit message #63:

sync

# This is the commit message #64:

sync

# This is the commit message #65:

sync

# This is the commit message #66:

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

No branches or pull requests

3 participants