Invalid memory address or nil pointer in POST _bulk_docs

I’m getting this error when posting certain data to the _bulk_docs API with Sync Gateway 2.5.1:

2020-03-04T14:19:05.956Z HTTP:  #6080392: POST /master/_bulk_docs  (as sgw_user)
    2020-03-04T14:19:05.957Z 	BulkDocs: Doc "da1a4680-5daa-11ea-b282-af43b2eec6b9" --> 409 Document revision conflict (409 Document revision conflict)
    2020-03-04 14:19:05.958480 I | http: panic serving 100.96.55.58:53366: runtime error: invalid memory address or nil pointer dereference
    goroutine 6099883 [running]:
    net/http.(*conn).serve.func1(0xc4286d8100)
	/usr/local/go/1.7.4/go/src/net/http/server.go:1491 +0x12a
    panic(0xb26840, 0xc420022050)
	/usr/local/go/1.7.4/go/src/runtime/panic.go:458 +0x243
    github.com/couchbase/sync_gateway/db.(*Database).updateAndReturnDoc(0xc429e1c7e0, 0xc42a6a92f0, 0x24, 0x7dab00, 0x0, 0xc423acf500, 0x410b18, 0x40, 0xb9f900, 0xbefb01, ...)
	/home/couchbase/jenkins/workspace/sgw-unix-build/1.5.1/enterprise/godeps/src/github.com/couchbase/sync_gateway/db/crud.go:995 +0x2264
github.com/couchbase/sync_gateway/db.(*Database).updateDoc(0xc429e1c7e0, 0xc42a6a92f0, 0x24, 0x0, 0xc423acf500, 0xc4278593f0, 0x4115e5, 0xc427859828, 0x10)
	/home/couchbase/jenkins/workspace/sgw-unix-build/1.5.1/enterprise/godeps/src/github.com/couchbase/sync_gateway/db/crud.go:717 +0x70
github.com/couchbase/sync_gateway/db.(*Database).Put(0xc429e1c7e0, 0xc42a6a92f0, 0x24, 0xc42a6a92c0, 0xc42762bb01, 0x0, 0xfc8880, 0xc4241fefc0)
	/home/couchbase/jenkins/workspace/sgw-unix-build/1.5.1/enterprise/godeps/src/github.com/couchbase/sync_gateway/db/crud.go:643 +0x356
github.com/couchbase/sync_gateway/rest.(*handler).handleBulkDocs(0xc427e87b00, 0x0, 0x0)
	/home/couchbase/jenkins/workspace/sgw-unix-build/1.5.1/enterprise/godeps/src/github.com/couchbase/sync_gateway/rest/bulk_api.go:446 +0x889
github.com/couchbase/sync_gateway/rest.(*handler).invoke(0xc427e87b00, 0xcb20f0, 0x0, 0x0)
	/home/couchbase/jenkins/workspace/sgw-unix-build/1.5.1/enterprise/godeps/src/github.com/couchbase/sync_gateway/rest/handler.go:221 +0x2c1
github.com/couchbase/sync_gateway/rest.makeHandler.func1(0xfcf500, 0xc42a278270, 0xc422d57c20)
	/home/couchbase/jenkins/workspace/sgw-unix-build/1.5.1/enterprise/godeps/src/github.com/couchbase/sync_gateway/rest/handler.go:96 +0x80
net/http.HandlerFunc.ServeHTTP(0xc420275a00, 0xfcf500, 0xc42a278270, 0xc422d57c20)
	/usr/local/go/1.7.4/go/src/net/http/server.go:1726 +0x44
github.com/gorilla/mux.(*Router).ServeHTTP(0xc42012a5f0, 0xfcf500, 0xc42a278270, 0xc422d57c20)
	/home/couchbase/jenkins/workspace/sgw-unix-build/1.5.1/enterprise/godeps/src/github.com/gorilla/mux/mux.go:114 +0x10d
github.com/couchbase/sync_gateway/rest.wrapRouter.func1(0xfcf500, 0xc42a278270, 0xc422d57a40)
	/home/couchbase/jenkins/workspace/sgw-unix-build/1.5.1/enterprise/godeps/src/github.com/couchbase/sync_gateway/rest/routing.go:300 +0x66f
net/http.HandlerFunc.ServeHTTP(0xc420382d20, 0xfcf500, 0xc42a278270, 0xc422d57a40)
	/usr/local/go/1.7.4/go/src/net/http/server.go:1726 +0x44
net/http.serverHandler.ServeHTTP(0xc42039a200, 0xfcf500, 0xc42a278270, 0xc422d57a40)
	/usr/local/go/1.7.4/go/src/net/http/server.go:2202 +0x7d
net/http.(*conn).serve(0xc4286d8100, 0xfd00c0, 0xc424e453c0)
	/usr/local/go/1.7.4/go/src/net/http/server.go:1579 +0x4b7
created by net/http.(*Server).Serve
	/usr/local/go/1.7.4/go/src/net/http/server.go:2293 +0x44d

Is this a known problem? Could it be related to Sync Gateway 2.0 invalid memory address or nil pointer dereference?

It looks like you’re running Sync Gateway 1.5.1, not 2.5.1 based on the stacktrace.

This panic was fixed in Sync Gateway 2.5.0:
https://issues.couchbase.com/browse/CBG-227

You’re so right. I did not even notice the version string in the stack trace. Looks like the wrong version of Sync Gateway got deployed.