Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
Snowflake WebExtension
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Cecylia Bocovich
Snowflake WebExtension
Commits
ed3d42e1
Commit
ed3d42e1
authored
5 years ago
by
Shane Howearth
Committed by
Cecylia Bocovich
5 years ago
Browse files
Options
Downloads
Patches
Plain Diff
Handle generated errors in server
parent
3ec9dd19
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
server/server.go
+29
-16
29 additions, 16 deletions
server/server.go
with
29 additions
and
16 deletions
server/server.go
+
29
−
16
View file @
ed3d42e1
...
...
@@ -4,7 +4,6 @@ package main
import
(
"crypto/tls"
"errors"
"flag"
"fmt"
"io"
...
...
@@ -75,7 +74,7 @@ func (conn *webSocketConn) Read(b []byte) (n int, err error) {
return
}
if
m
.
Opcode
!=
2
{
err
=
errors
.
New
(
fmt
.
Sprint
f
(
"got non-binary opcode %d"
,
m
.
Opcode
)
)
err
=
fmt
.
Error
f
(
"got non-binary opcode %d"
,
m
.
Opcode
)
return
}
conn
.
messageBuf
=
m
.
Payload
...
...
@@ -113,20 +112,22 @@ func proxy(local *net.TCPConn, conn *webSocketConn) {
wg
.
Add
(
2
)
go
func
()
{
_
,
err
:=
io
.
Copy
(
conn
,
local
)
if
err
!=
nil
{
log
.
Printf
(
"error copying ORPort to WebSocket"
)
if
_
,
err
:=
io
.
Copy
(
conn
,
local
);
err
!=
nil
{
log
.
Printf
(
"error copying ORPort to WebSocket %v"
,
err
)
}
if
err
:=
local
.
CloseRead
();
err
!=
nil
{
log
.
Printf
(
"error closing read after copying ORPort to WebSocket %v"
,
err
)
}
local
.
CloseRead
()
conn
.
Close
()
wg
.
Done
()
}()
go
func
()
{
_
,
err
:=
io
.
Copy
(
local
,
conn
)
if
err
!=
nil
{
if
_
,
err
:=
io
.
Copy
(
local
,
conn
);
err
!=
nil
{
log
.
Printf
(
"error copying WebSocket to ORPort"
)
}
local
.
CloseWrite
()
if
err
:=
local
.
CloseWrite
();
err
!=
nil
{
log
.
Printf
(
"error closing write after copying WebSocket to ORPort %v"
,
err
)
}
conn
.
Close
()
wg
.
Done
()
}()
...
...
@@ -150,7 +151,9 @@ func clientAddr(clientIPParam string) string {
func
webSocketHandler
(
ws
*
websocket
.
WebSocket
)
{
// Undo timeouts on HTTP request handling.
ws
.
Conn
.
SetDeadline
(
time
.
Time
{})
if
err
:=
ws
.
Conn
.
SetDeadline
(
time
.
Time
{});
err
!=
nil
{
log
.
Printf
(
"unable to set deadlines with error: %v"
,
err
)
}
conn
:=
newWebSocketConn
(
ws
)
defer
conn
.
Close
()
...
...
@@ -307,7 +310,8 @@ func main() {
log
.
Printf
(
"ACME hostnames: %q"
,
acmeHostnames
)
var
cache
autocert
.
Cache
cacheDir
,
err
:=
getCertificateCacheDir
()
var
cacheDir
string
cacheDir
,
err
=
getCertificateCacheDir
()
if
err
==
nil
{
log
.
Printf
(
"caching ACME certificates in directory %q"
,
cacheDir
)
cache
=
autocert
.
DirCache
(
cacheDir
)
...
...
@@ -332,7 +336,9 @@ func main() {
servers
:=
make
([]
*
http
.
Server
,
0
)
for
_
,
bindaddr
:=
range
ptInfo
.
Bindaddrs
{
if
bindaddr
.
MethodName
!=
ptMethodName
{
pt
.
SmethodError
(
bindaddr
.
MethodName
,
"no such method"
)
if
err
=
pt
.
SmethodError
(
bindaddr
.
MethodName
,
"no such method"
);
err
!=
nil
{
log
.
Printf
(
"pt.SmethodError returned error: %v"
,
err
)
}
continue
}
...
...
@@ -340,10 +346,13 @@ func main() {
addr
:=
*
bindaddr
.
Addr
addr
.
Port
=
80
log
.
Printf
(
"Starting HTTP-01 ACME listener"
)
lnHTTP01
,
err
:=
net
.
ListenTCP
(
"tcp"
,
&
addr
)
var
lnHTTP01
*
net
.
TCPListener
lnHTTP01
,
err
=
net
.
ListenTCP
(
"tcp"
,
&
addr
)
if
err
!=
nil
{
log
.
Printf
(
"error opening HTTP-01 ACME listener: %s"
,
err
)
pt
.
SmethodError
(
bindaddr
.
MethodName
,
"HTTP-01 ACME listener: "
+
err
.
Error
())
if
inerr
:=
pt
.
SmethodError
(
bindaddr
.
MethodName
,
"HTTP-01 ACME listener: "
+
err
.
Error
());
inerr
!=
nil
{
log
.
Printf
(
"pt.SmethodError returned error: %v"
,
inerr
)
}
continue
}
server
:=
&
http
.
Server
{
...
...
@@ -371,7 +380,9 @@ func main() {
}
if
err
!=
nil
{
log
.
Printf
(
"error opening listener: %s"
,
err
)
pt
.
SmethodError
(
bindaddr
.
MethodName
,
err
.
Error
())
if
inerr
:=
pt
.
SmethodError
(
bindaddr
.
MethodName
,
err
.
Error
());
inerr
!=
nil
{
log
.
Printf
(
"pt.SmethodError returned error: %v"
,
inerr
)
}
continue
}
pt
.
SmethodArgs
(
bindaddr
.
MethodName
,
bindaddr
.
Addr
,
args
)
...
...
@@ -388,7 +399,9 @@ func main() {
// This environment variable means we should treat EOF on stdin
// just like SIGTERM: https://bugs.torproject.org/15435.
go
func
()
{
io
.
Copy
(
ioutil
.
Discard
,
os
.
Stdin
)
if
_
,
err
:=
io
.
Copy
(
ioutil
.
Discard
,
os
.
Stdin
);
err
!=
nil
{
log
.
Printf
(
"error copying os.Stdin to ioutil.Discard: %v"
,
err
)
}
log
.
Printf
(
"synthesizing SIGTERM because of stdin close"
)
sigChan
<-
syscall
.
SIGTERM
}()
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment