googleapis / googleapis/gapic-showcase

server panics when field mask is missing

Open
#1,281 0 comments 0 reactions 0 assignees View on GitHub
priority: p2 type: bug
Dominant language
Go
Stars
183
Forks
55
Avg merge
1d 1h
Merged PRs (30d)
8

Description

If a request is missing a field mask when the server expects it, Showcase panics rather than logging/returning a descriptive error.

I ran into this in the course of investigating #1263.

Reproduction steps:

After starting the server, issue the following requests:

```
# works; note that if we set the field "name" it gets overriden by the server
curl -H "X-Goog-Api-Client: rest/0.0.0 gapic/0.0.0" -H 'Content-Type: application/json' -i -X POST http://localhost:7469/v1beta1/users -d'{"user":{"displayName":"JaneDoe","email":"janedoe@example.com","nickname":"Doe","heightFeet":5.0,"enableNotifications":true}}'

# works
curl -H "X-Goog-Api-Client: rest/0.0.0 gapic/0.0.0" -H 'Content-Type: application/json' -i -X GET http://localhost:7469/v1beta1/users

# works
curl -H "X-Goog-Api-Client: rest/0.0.0 gapic/0.0.0" -H 'Content-Type: application/json' -i -X PATCH http://localhost:7469/v1beta1/users/0?updateMask=\"email,heightFeet,enableNotifications\" -d'{"displayName":"JaneDoe","email":"janedoe@jane.com","heightFeet":6.0,"enableNotifications":true}'

# panics because of missing field mask
curl -H "X-Goog-Api-Client: rest/0.0.0 gapic/0.0.0" -H 'Content-Type: application/json' -i -X PATCH http://localhost:7469/v1beta1/users/0 -d'{"displayName":"JanetDoe","email":"janetdoe@jane.com","heightFeet":7.0,"enableNotifications":true}'
# curl responds with: curl: (52) Empty reply from server
```

The panic message in the server logs is
```
2023/03/22 13:34:19 http: panic serving 127.0.0.1:37604: field google.showcase.v1beta1.User.create_time has invalid nil pointer
goroutine 101 [running]:
net/http.(*conn).serve.func1()
/usr/lib/google-golang/src/net/http/server.go:1853 +0xbf
panic({0xba5de0, 0xc0005b5320})
/usr/lib/google-golang/src/runtime/panic.go:890 +0x263
google.golang.org/protobuf/internal/impl.fieldInfoForMessage.func4({0xc0001a7200?}, {{}, 0xcb8220?, 0xc0000aa460?, 0xc0000aa740?})
/usr/local/google/home/vchudnov/VeneerToolkit/compute-gapic/showcase3/gopath/pkg/mod/google.golang.org/protobuf@v1.30.0/internal/impl/message_reflect_field.go:447 +0x20b
google.golang.org/protobuf/internal/impl.(*messageState).Set(0xc0002621b0, {0xe11710?, 0xc0001514d0?}, {{}, 0xcb8220?, 0xc0000aa460?, 0xbfb680?})
/usr/local/google/home/vchudnov/VeneerToolkit/compute-gapic/showcase3/gopath/pkg/mod/google.golang.org/protobuf@v1.30.0/internal/impl/message_reflect_gen.go:91 +0x10b
github.com/googleapis/gapic-showcase/server/services.applyFieldMask({0xe0c210, 0xc000262090}, {0xe0c210, 0xc0002621b0}, {0x0, 0x0, 0xc82040?})
/usr/local/google/home/vchudnov/VeneerToolkit/dev/gapic-showcase/server/services/util.go:47 +0x224
github.com/googleapis/gapic-showcase/server/services.(*identityServerImpl).UpdateUser(0xc0003e29c0, {0xc00045c630?, 0xba40a0?}, 0xdf9f90?)
/usr/local/google/home/vchudnov/VeneerToolkit/dev/gapic-showcase/server/services/identity_service.go:131 +0x24d
github.com/googleapis/gapic-showcase/server/genrest.(*RESTBackend).HandleUpdateUser(0xc0003cfe40, {0xe04be0, 0xc000213960}, 0xc000423300)
/usr/local/google/home/vchudnov/VeneerToolkit/dev/gapic-showcase/server/genrest/identity.go:229 +0xaa3
net/http.HandlerFunc.ServeHTTP(0xc000423200?, {0xe04be0?, 0xc000213960?}, 0xc0000a29e8?)
/usr/lib/google-golang/src/net/http/server.go:2121 +0x2f
github.com/gorilla/mux.(*Router).ServeHTTP(0xc000000e40, {0xe04be0, 0xc000213960}, 0xc000423100)
/usr/local/google/home/vchudnov/VeneerToolkit/compute-gapic/showcase3/gopath/pkg/mod/github.com/gorilla/mux@v1.8.0/mux.go:210 +0x1cf
net/http.serverHandler.ServeHTTP({0xe02188?}, {0xe04be0, 0xc000213960}, 0xc000423100)
/usr/lib/google-golang/src/net/http/server.go:2935 +0x316
net/http.(*conn).serve(0xc0001fa870, {0xe05500, 0xc0005a2e70})
/usr/lib/google-golang/src/net/http/server.go:1994 +0x612
created by net/http.(*Server).Serve
/usr/lib/google-golang/src/net/http/server.go:3090 +0x61b
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.