File tree 4 files changed +34
-6
lines changed
4 files changed +34
-6
lines changed Original file line number Diff line number Diff line change @@ -53,10 +53,26 @@ func (s *Server) signalHandler(data []byte) {
53
53
s .lock .Lock ()
54
54
defer s .lock .Unlock ()
55
55
56
+ deleteConnection := func (connection * websocket.Conn ) {
57
+ delete (s .connections , connection )
58
+ err := connection .Close ()
59
+ if err != nil {
60
+ log .Error ("failed to close connection" , "error" , err )
61
+ }
62
+ }
63
+
56
64
for connection := range s .connections {
57
- err := connection .WriteMessage (websocket .TextMessage , data )
65
+ err := connection .SetWriteDeadline (time .Now ().Add (5 * time .Second ))
66
+ if err != nil {
67
+ log .Error ("failed to set write deadline" , "error" , err )
68
+ deleteConnection (connection )
69
+ continue
70
+ }
71
+
72
+ err = connection .WriteMessage (websocket .TextMessage , data )
58
73
if err != nil {
59
- log .Error ("failed to write message: %w" , err )
74
+ log .Error ("failed to write signal message" , "error" , err )
75
+ deleteConnection (connection )
60
76
}
61
77
}
62
78
}
@@ -130,6 +146,7 @@ func (s *Server) signals(w http.ResponseWriter, r *http.Request) {
130
146
log .Error ("failed to upgrade connection: %w" , err )
131
147
return
132
148
}
149
+ log .Debug ("new websocket connection" )
133
150
134
151
s .connections [connection ] = struct {}{}
135
152
}
Original file line number Diff line number Diff line change @@ -318,7 +318,7 @@ func main() {
318
318
319
319
// Check if profiling shall be enabled.
320
320
if * pprofEnabled {
321
- profiling .NewProfiler (* pprofPort ).Go ()
321
+ profiling .NewProfiler (fmt . Sprintf ( ":%d" , * pprofPort ) ).Go ()
322
322
}
323
323
324
324
if config .PushNotificationServerConfig .Enabled {
Original file line number Diff line number Diff line change 5
5
"encoding/json"
6
6
"errors"
7
7
"fmt"
8
+ "runtime"
8
9
"unsafe"
9
10
10
11
"go.uber.org/zap"
@@ -1071,6 +1072,17 @@ func writeHeapProfile(dataDir string) string { //nolint: deadcode
1071
1072
return makeJSONResponse (err )
1072
1073
}
1073
1074
1075
+ // StartProfiling starts profiling and HTTP server for pprof
1076
+ func StartProfiling (address string ) string {
1077
+ return callWithResponse (startProfiling , address )
1078
+ }
1079
+
1080
+ func startProfiling (address string ) string {
1081
+ runtime .SetMutexProfileFraction (5 )
1082
+ profiling .NewProfiler (address ).Go ()
1083
+ return makeJSONResponse (nil )
1084
+ }
1085
+
1074
1086
func makeJSONResponse (err error ) string {
1075
1087
errString := ""
1076
1088
if err != nil {
Original file line number Diff line number Diff line change 1
1
package profiling
2
2
3
3
import (
4
- "fmt"
5
4
"net/http"
6
5
hpprof "net/http/pprof"
7
6
"time"
@@ -19,7 +18,7 @@ type Profiler struct {
19
18
20
19
// NewProfiler creates an instance of the profiler with
21
20
// the given port.
22
- func NewProfiler (port int ) * Profiler {
21
+ func NewProfiler (address string ) * Profiler {
23
22
mux := http .NewServeMux ()
24
23
mux .HandleFunc ("/debug/pprof/" , hpprof .Index )
25
24
mux .HandleFunc ("/debug/pprof/cmdline" , hpprof .Cmdline )
@@ -28,7 +27,7 @@ func NewProfiler(port int) *Profiler {
28
27
mux .HandleFunc ("/debug/pprof/trace" , hpprof .Trace )
29
28
p := Profiler {
30
29
server : & http.Server {
31
- Addr : fmt . Sprintf ( ":%d" , port ) ,
30
+ Addr : address ,
32
31
ReadHeaderTimeout : 5 * time .Second ,
33
32
Handler : mux ,
34
33
},
You can’t perform that action at this time.
0 commit comments