90
case <-cctx.Context().Done():
91
return
92
case <-tmo.C:
93
- tmo.Reset(configPollInterval)
94
- }
95
-
96
- // reread the config, which may have changed in the meantime
97
- cfg, err := cctx.GetConfig()
98
- if err != nil {
99
- mfslog.Errorf("pinning reading config (%v)", err)
100
- continue
101
- }
102
- mfslog.Debugf("pinning loop is awake, %d remote services", len(cfg.Pinning.RemoteServices))
93
+ // reread the config, which may have changed in the meantime
94
+ cfg, err := cctx.GetConfig()
95
+ if err != nil {
96
+ mfslog.Errorf("pinning reading config (%v)", err)
97
+ continue
98
+ }
99
+ mfslog.Debugf("pinning loop is awake, %d remote services", len(cfg.Pinning.RemoteServices))
100
104
- // get the most recent MFS root cid
105
- rootNode, err := node.RootNode()
106
- if err != nil {
107
- mfslog.Errorf("pinning reading MFS root (%v)", err)
108
- continue
101
+ // pin to all remote services in parallel
102
+ pinAllMFS(cctx.Context(), node, cfg, lastPins)
103
}
110
-
111
- // pin to all remote services in parallel
112
- pinAllMFS(cctx.Context(), node, cfg, rootNode.Cid(), lastPins)
104
+ // pinAllMFS may take long. Reset interval only when we are done doing it
105
+ // so that we are not pinning constantly.
106
+ tmo.Reset(configPollInterval)
107
}
108
}
109
110
// pinAllMFS pins on all remote services in parallel to overcome DoS attacks.
117
-func pinAllMFS(ctx context.Context, node pinMFSNode, cfg *config.Config, rootCid cid.Cid, lastPins map[string]lastPin) {
111
+func pinAllMFS(ctx context.Context, node pinMFSNode, cfg *config.Config, lastPins map[string]lastPin) {
112
ch := make(chan lastPin)
113
var started int
114
115
+ // Bail out to mitigate issue below when not needing to do anything.
116
+ if len(cfg.Pinning.RemoteServices) == 0 {
117
+ return
118
+ }
119
+
120
+ // get the most recent MFS root cid.
121
+ // Warning! This can be super expensive.
122
+ // See https://github.com/ipfs/boxo/pull/751
123
+ // and https://github.com/ipfs/kubo/issues/8694
124
+ // Reading an MFS-directory nodes can take minutes due to
125
+ // ever growing cache being synced to unixfs.
126
+ rootNode, err := node.RootNode()
127
+ if err != nil {
128
+ mfslog.Errorf("pinning reading MFS root (%v)", err)
129
+ return
130
+ }
131
+ rootCid := rootNode.Cid()
132
+
133
for svcName, svcConfig := range cfg.Pinning.RemoteServices {
134
if ctx.Err() != nil {
135
break