Skip to content

Commit b639370

Browse files
committed
fix review
1 parent e2e15b5 commit b639370

File tree

3 files changed

+15
-26
lines changed

3 files changed

+15
-26
lines changed

Diff for: examples/features/debugging/README.md

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,18 @@
11
# Debugging
22

3+
Currently, grpc provides two major tools to help user debug issues, which are logging and channelz.
4+
5+
## Logs
36
gRPC has put substantial logging instruments on critical paths of gRPC to help users debug issues.
47
The [Log Levels](https://github.com/grpc/grpc-go/blob/master/Documentation/log_levels.md) doc describes
58
what each log level means in the gRPC context.
69

7-
We also provides a runtime debugging tool, Channelz, to help users with live debugging.
8-
9-
## Logs
1010
To turn on the logs for debugging, run the code with the following environment variable:
1111
`GRPC_GO_LOG_VERBOSITY_LEVEL=99 GRPC_GO_LOG_SEVERITY_LEVEL=info`.
1212

1313
## Channelz
14+
We also provides a runtime debugging tool, Channelz, to help users with live debugging.
15+
1416
See the channelz blog post here ([link](https://grpc.io/blog/a_short_introduction_to_channelz)) for
1517
details about how to use channelz service to debug live program.
1618

Diff for: examples/features/debugging/client/main.go

+6-8
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,13 @@
1616
*
1717
*/
1818

19+
// Binary client is an example client.
1920
package main
2021

2122
import (
2223
"log"
2324
"net"
2425
"os"
25-
"os/signal"
2626
"time"
2727

2828
"golang.org/x/net/context"
@@ -39,10 +39,11 @@ const (
3939

4040
func main() {
4141
/***** Set up the server serving channelz service. *****/
42-
lis, err := net.Listen("tcp", ":50050")
42+
lis, err := net.Listen("tcp", ":50052")
4343
if err != nil {
4444
log.Fatalf("failed to listen: %v", err)
4545
}
46+
defer lis.Close()
4647
s := grpc.NewServer()
4748
service.RegisterChannelzServiceToServer(s)
4849
go s.Serve(lis)
@@ -81,11 +82,8 @@ func main() {
8182
}
8283
}
8384

84-
/***** Wait for CTRL+C to exit *****/
85-
// Unless you exit the program with CTRL+C, channelz data will be available for querying.
85+
/***** Wait for user exiting the program *****/
86+
// Unless you exit the program (e.g. CTRL+C), channelz data will be available for querying.
8687
// Users can take time to examine and learn about the info provided by channelz.
87-
ch := make(chan os.Signal, 1)
88-
signal.Notify(ch, os.Interrupt)
89-
// Block until a signal is received.
90-
<-ch
88+
select {}
9189
}

Diff for: examples/features/debugging/server/main.go

+4-15
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,12 @@
1616
*
1717
*/
1818

19+
// Binary server is an example server.
1920
package main
2021

2122
import (
2223
"log"
2324
"net"
24-
"os"
25-
"os/signal"
2625
"time"
2726

2827
"golang.org/x/net/context"
@@ -67,16 +66,13 @@ func main() {
6766
defer s.Stop()
6867

6968
/***** Start three GreeterServers(with one of them to be the slowServer). *****/
70-
var listeners []net.Listener
71-
var svrs []*grpc.Server
7269
for i := 0; i < 3; i++ {
7370
lis, err := net.Listen("tcp", ports[i])
7471
if err != nil {
7572
log.Fatalf("failed to listen: %v", err)
7673
}
77-
listeners = append(listeners, lis)
74+
defer lis.Close()
7875
s := grpc.NewServer()
79-
svrs = append(svrs, s)
8076
if i == 2 {
8177
pb.RegisterGreeterServer(s, &slowServer{})
8278
} else {
@@ -85,13 +81,6 @@ func main() {
8581
go s.Serve(lis)
8682
}
8783

88-
/***** Wait for CTRL+C to exit *****/
89-
ch := make(chan os.Signal, 1)
90-
signal.Notify(ch, os.Interrupt)
91-
// Block until a signal is received.
92-
<-ch
93-
for i := 0; i < 3; i++ {
94-
svrs[i].Stop()
95-
listeners[i].Close()
96-
}
84+
/***** Wait for user exiting the program *****/
85+
select {}
9786
}

0 commit comments

Comments
 (0)