Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
N
nebula
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
exchain
nebula
Commits
cf4939e8
Unverified
Commit
cf4939e8
authored
Aug 14, 2023
by
OptimismBot
Committed by
GitHub
Aug 14, 2023
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6785 from ethereum-optimism/jg/fix_url_dial
Fix IsURLAvailable
parents
234351c3
454613f9
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
47 additions
and
2 deletions
+47
-2
dial_test.go
op-node/client/dial_test.go
+34
-1
rpc.go
op-node/client/rpc.go
+13
-1
No files found.
op-node/client/dial_test.go
View file @
cf4939e8
...
...
@@ -9,7 +9,7 @@ import (
"github.com/stretchr/testify/require"
)
func
TestIsURLAvailable
(
t
*
testing
.
T
)
{
func
TestIsURLAvailable
Local
(
t
*
testing
.
T
)
{
listener
,
err
:=
net
.
Listen
(
"tcp4"
,
":0"
)
require
.
NoError
(
t
,
err
)
defer
listener
.
Close
()
...
...
@@ -18,6 +18,39 @@ func TestIsURLAvailable(t *testing.T) {
parts
:=
strings
.
Split
(
a
,
":"
)
addr
:=
fmt
.
Sprintf
(
"http://localhost:%s"
,
parts
[
1
])
// True & False with ports
require
.
True
(
t
,
IsURLAvailable
(
addr
))
require
.
False
(
t
,
IsURLAvailable
(
"http://localhost:0"
))
// Fail open if we don't recognize the scheme
require
.
True
(
t
,
IsURLAvailable
(
"mailto://example.com"
))
}
func
TestIsURLAvailableNonLocal
(
t
*
testing
.
T
)
{
if
!
IsURLAvailable
(
"http://example.com"
)
{
t
.
Skip
(
"No internet connection found, skipping this test"
)
}
// True without ports. http & https
require
.
True
(
t
,
IsURLAvailable
(
"http://example.com"
))
require
.
True
(
t
,
IsURLAvailable
(
"http://example.com/hello"
))
require
.
True
(
t
,
IsURLAvailable
(
"https://example.com"
))
require
.
True
(
t
,
IsURLAvailable
(
"https://example.com/hello"
))
// True without ports. ws & wss
require
.
True
(
t
,
IsURLAvailable
(
"ws://example.com"
))
require
.
True
(
t
,
IsURLAvailable
(
"ws://example.com/hello"
))
require
.
True
(
t
,
IsURLAvailable
(
"wss://example.com"
))
require
.
True
(
t
,
IsURLAvailable
(
"wss://example.com/hello"
))
// False without ports
require
.
False
(
t
,
IsURLAvailable
(
"http://fakedomainnamethatdoesnotexistandshouldneverexist.com"
))
require
.
False
(
t
,
IsURLAvailable
(
"http://fakedomainnamethatdoesnotexistandshouldneverexist.com/hello"
))
require
.
False
(
t
,
IsURLAvailable
(
"https://fakedomainnamethatdoesnotexistandshouldneverexist.com"
))
require
.
False
(
t
,
IsURLAvailable
(
"https://fakedomainnamethatdoesnotexistandshouldneverexist.com/hello"
))
require
.
False
(
t
,
IsURLAvailable
(
"ws://fakedomainnamethatdoesnotexistandshouldneverexist.com"
))
require
.
False
(
t
,
IsURLAvailable
(
"ws://fakedomainnamethatdoesnotexistandshouldneverexist.com/hello"
))
require
.
False
(
t
,
IsURLAvailable
(
"wss://fakedomainnamethatdoesnotexistandshouldneverexist.com"
))
require
.
False
(
t
,
IsURLAvailable
(
"wss://fakedomainnamethatdoesnotexistandshouldneverexist.com/hello"
))
}
op-node/client/rpc.go
View file @
cf4939e8
...
...
@@ -122,7 +122,19 @@ func IsURLAvailable(address string) bool {
if
err
!=
nil
{
return
false
}
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
u
.
Host
,
5
*
time
.
Second
)
addr
:=
u
.
Host
if
u
.
Port
()
==
""
{
switch
u
.
Scheme
{
case
"http"
,
"ws"
:
addr
+=
":80"
case
"https"
,
"wss"
:
addr
+=
":443"
default
:
// Fail open if we can't figure out what the port should be
return
true
}
}
conn
,
err
:=
net
.
DialTimeout
(
"tcp"
,
addr
,
5
*
time
.
Second
)
if
err
!=
nil
{
return
false
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment