owncloud / owncloud/ocis

Introduce ocis-pkg/RegisterChiMethodOnce

Open
#6,924 0 comments 0 reactions 0 assignees View on GitHub
Type:Bug
Dominant language
Go
Stars
2.1k
Forks
274
Avg merge
2d 1h
Merged PRs (30d)
103

Description

We should use an `ocis-pkg/chi RegisterMethodOnce(method string)` function that executes the chi call once per method. That would be a cleaner solution than the `MethodNotAllowed` workaround: we can then propery register routes ... or we submit an upstream Fix, duh ...

Related:
* https://github.com/owncloud/ocis/pull/3662
* https://github.com/owncloud/ocis/pull/6921

Our current workaround might have sideeffects in the future: https://github.com/go-chi/chi/pull/776

Hm from the original workaround in #3662:
> chi.RegisterMethod writes to a global map. Other parts of chi read that map and since we start multiple chi router in different goroutines we concurrently read/write to the map which is not valid and results in panics

These other parts are Method and MethodFunc calls, which try to read from the global map. Depending on the order in which services are started the webdav or proxy service might write to the chi `methodMap` while another service is trying to register a route and as a result reading from the `methodMap` in setEndpoint ...

hm, the chi examples just use init:
https://github.com/go-chi/chi/blob/master/_examples/custom-method/main.go
```go
func init() {
chi.RegisterMethod("LINK")
chi.RegisterMethod("UNLINK")
chi.RegisterMethod("WOOHOO")
}
```

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.