-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Playground: Fix pass bound hostname to run sessions #12356
Conversation
bug: I had two servers(A and B, they both are in same local area network by one WIFI): A: ip 192.168.8.83, Unbuntu 18 B: Windows10 when run ```crystal play -p 3566 -b 192.168.8.83 -v``` in server A, then open http://192.168.8.83:3566/ in Chrome then click start button will get this error: ``` Unhandled exception: Error connecting to 'localhost:3566': Connection refused (Socket::ConnectError) from /home/myth/crystal/crystal-1.3.2-1/share/crystal/src/socket/addrinfo.cr:67:17 in 'initialize' from /home/myth/crystal/crystal-1.3.2-1/share/crystal/src/socket/tcp_socket.cr:27:3 in 'initialize' from /home/myth/crystal/crystal-1.3.2-1/share/crystal/src/socket/tcp_socket.cr:27:3 in 'new' from /home/myth/crystal/crystal-1.3.2-1/share/crystal/src/http/web_socket/protocol.cr:275:5 in 'new' from /home/myth/crystal/crystal-1.3.2-1/share/crystal/src/http/web_socket/protocol.cr:326:14 in 'new' from /home/myth/crystal/crystal-1.3.2-1/share/crystal/src/http/web_socket.cr:37:5 in 'new' from /home/myth/crystal/crystal-1.3.2-1/share/crystal/src/http/web_socket.cr:36:3 in 'new' from /home/myth/crystal/crystal-1.3.2-1/share/crystal/src/compiler/crystal/tools/playground/agent.cr:8:11 in 'initialize' from /home/myth/crystal/crystal-1.3.2-1/share/crystal/src/compiler/crystal/tools/playground/agent.cr:7:3 in 'new' from playground_prelude:5:24 in '~Crystal::Playground::Agent::instance:init' from play:1:6 in '__crystal_main' from /home/myth/crystal/crystal-1.3.2-1/share/crystal/src/crystal/main.cr:115:5 in 'main_user_code' from /home/myth/crystal/crystal-1.3.2-1/share/crystal/src/crystal/main.cr:101:7 in 'main' from /home/myth/crystal/crystal-1.3.2-1/share/crystal/src/crystal/main.cr:127:3 in 'main' from /lib/x86_64-linux-gnu/libc.so.6 in '__libc_start_main' from /home/myth/.cache/crystal/crystal-run-play-1-1.tmp in '_start' from ??? exit status: 1 ```
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The best way to get a working value is probably to use the actual bind address. We're currently only using the port from that, but it should use the entire address.
@@ -10,7 +10,7 @@ module Crystal::Playground | |||
class Session | |||
getter tag : Int32 | |||
|
|||
def initialize(@ws : HTTP::WebSocket, @session_key : Int32, @port : Int32) | |||
def initialize(@ws : HTTP::WebSocket, @session_key : Int32, @port : Int32, @@host : String | Nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be an instance variable, not a class variable, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I first use instance variable @host
, but got error:
26 | ip = @host
^----
Error: @instance_vars are not yet allowed in metaclasses: use @@class_vars instead
So change to @@host
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's not a proper solution. The error appears because you tried to access the ivar directly from a class method. That doesn't work because it's not bound to an instance. You should pass the ivar value to the class method, just like @port
(or just combine them into @address
, which probably makes even more sense).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thanks! I had try to modify it by another commit right now!
|
||
|
||
ip = @@host | ||
ip = "localhost" if ip == "127.0.0.1" || ip == "localhost" || ip == nil |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct. You can't assume nil or 127.0.0.1
mean localhost
.
Also, any kind of modification should happen already at the server, not in each session.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct. You can't assume nil or
127.0.0.1
meanlocalhost
. Also, any kind of modification should happen already at the server, not in each session.
yes, I also don't think is correct , I assume if specify the -b
then use ip of -b
instead of default localhost
. I just try to improve that becuase the raw code is alaways localhost
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct. You can't assume nil or
127.0.0.1
meanlocalhost
. Also, any kind of modification should happen already at the server, not in each session.
sorry,I jgot your idea just now, should modification the ip outside of each session!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think this is correct. You can't assume nil or
127.0.0.1
meanlocalhost
. Also, any kind of modification should happen already at the server, not in each session.
I had try to fix it in my second commit~
update
yes, currently only use port from that and alaways |
For correct behaviour, you must use the exact address returned from |
ok, now the last commit is using the exact address returned from |
Sorry, I didn't mean to start a new server. That's completely unnecessary. The address is already available from the existing call to
We're already using the port from that address. Instead, we should store the entire address and use that everywhere in place of host + port. |
ok, now change to use the existsed address ip instead of start a new server in the last commit~ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant newlines
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
Co-authored-by: Sijawusz Pur Rahnama <[email protected]>
localhost
got 1 failing check as above, and the log as below, is the network not working so can't docker pull crystallang/crystal:1.0.0-build ?
|
There seems to have been some connectivity issues with the docker registry in several CI runs. They are sporadic and unrelated to any code changes, so we just ignore them or try again. |
ok,thanks for the explanation because I am not familiar with the github CI runs~ |
localhost
I test crystal-1.5.0-1 and crystal-1.3.2-1 both got this bug:
I have two servers(A and B, they both are in same local area network by one WIFI):
A: ip 192.168.8.83, Unbuntu 18
B: Windows10
when run
crystal play -p 3566 -b 192.168.8.83 -v
in server A, then open http://192.168.8.83:3566/ in Chrome at server B then click start button will get this error:Update:
when I change
@@instance = Crystal::Playground::Agent.new("ws://localhost:#{port}/agent/#{session_key}/#{tag}", #{tag})
of src/compiler/crystal/tools/playground/server.cr to@@instance = Crystal::Playground::Agent.new("ws://192.168.8.83:#{port}/agent/#{session_key}/#{tag}", #{tag})
and rebuild crystal, it works !