Skip to content

Commit

Permalink
Properly lock access to the shared map
Browse files Browse the repository at this point in the history
  • Loading branch information
glpatcern committed Aug 4, 2020
1 parent 11567bc commit 8d2ffa9
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ description: >
# _struct: config_

{{% dir name="iopsecret" type="string" default="" %}}
The iopsecret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L60)
The iopsecret used to connect to the wopiserver. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L61)
{{< highlight toml >}}
[grpc.services.appprovider]
iopsecret = ""
{{< /highlight >}}
{{% /dir %}}

{{% dir name="wopiurl" type="string" default="" %}}
The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L61)
The wopiserver's URL. [[Ref]](https://github.com/cs3org/reva/tree/master/internal/grpc/services/appprovider/appprovider.go#L62)
{{< highlight toml >}}
[grpc.services.appprovider]
wopiurl = ""
Expand Down
18 changes: 12 additions & 6 deletions internal/grpc/services/appprovider/appprovider.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import (
"path"
"strconv"
"strings"
"sync"
"time"

providerpb "github.com/cs3org/go-cs3apis/cs3/app/provider/v1beta1"
Expand Down Expand Up @@ -157,15 +158,20 @@ func (s *service) OpenFileInAppProvider(ctx context.Context, req *providerpb.Ope

log := appctx.GetLogger(ctx)

var mutex = &sync.Mutex{}
if s.appsURLMap == nil {
// TODO refresh after e.g. a day or a week
err := s.getWopiAppEndpoints(ctx)
if err != nil {
res := &providerpb.OpenFileInAppProviderResponse{
Status: status.NewInternal(ctx, err, "appprovider: getWopiAppEndpoints failed"),
mutex.Lock()
if s.appsURLMap == nil {
// TODO refresh after e.g. a day or a week
err := s.getWopiAppEndpoints(ctx)
if err != nil {
res := &providerpb.OpenFileInAppProviderResponse{
Status: status.NewInternal(ctx, err, "appprovider: getWopiAppEndpoints failed"),
}
return res, nil
}
return res, nil
}
mutex.Unlock()
}

httpClient := rhttp.GetHTTPClient(
Expand Down

0 comments on commit 8d2ffa9

Please sign in to comment.