@@ -82,29 +82,20 @@ func (sc *sourceCoordinator) getSourceGatewayFor(ctx context.Context, id Project
82
82
83
83
// No gateway exists for this path yet; set up a proto, being careful to fold
84
84
// together simultaneous attempts on the same path.
85
- rc := srcReturnChans {
86
- ret : make (chan * sourceGateway ),
87
- err : make (chan error ),
88
- }
89
-
90
- // The rest of the work needs its own goroutine, the results of which will
91
- // be re-joined to this call via the return chans.
92
- go sc .setUpSourceGateway (ctx , normalizedName , rc )
93
- return rc .awaitReturn ()
94
- }
95
-
96
- // Not intended to be called externally - call getSourceGatewayFor instead.
97
- func (sc * sourceCoordinator ) setUpSourceGateway (ctx context.Context , normalizedName string , rc srcReturnChans ) {
98
85
sc .psrcmut .Lock ()
99
86
if chans , has := sc .protoSrcs [normalizedName ]; has {
100
87
// Another goroutine is already working on this normalizedName. Fold
101
88
// in with that work by attaching our return channels to the list.
89
+ rc := srcReturnChans {
90
+ ret : make (chan * sourceGateway , 1 ),
91
+ err : make (chan error , 1 ),
92
+ }
102
93
sc .protoSrcs [normalizedName ] = append (chans , rc )
103
94
sc .psrcmut .Unlock ()
104
- return
95
+ return rc . awaitReturn ()
105
96
}
106
97
107
- sc .protoSrcs [normalizedName ] = []srcReturnChans {rc }
98
+ sc .protoSrcs [normalizedName ] = []srcReturnChans {}
108
99
sc .psrcmut .Unlock ()
109
100
110
101
doReturn := func (sg * sourceGateway , err error ) {
@@ -130,7 +121,7 @@ func (sc *sourceCoordinator) setUpSourceGateway(ctx context.Context, normalizedN
130
121
// As in the deducer, don't cache errors so that externally-driven retry
131
122
// strategies can be constructed.
132
123
doReturn (nil , err )
133
- return
124
+ return nil , err
134
125
}
135
126
136
127
// It'd be quite the feat - but not impossible - for a gateway
@@ -144,7 +135,7 @@ func (sc *sourceCoordinator) setUpSourceGateway(ctx context.Context, normalizedN
144
135
if srcGate , has := sc .srcs [url ]; has {
145
136
sc .srcmut .RUnlock ()
146
137
doReturn (srcGate , nil )
147
- return
138
+ return srcGate , nil
148
139
}
149
140
panic (fmt .Sprintf ("%q was URL for %q in nameToURL, but no corresponding srcGate in srcs map" , url , normalizedName ))
150
141
}
@@ -165,7 +156,7 @@ func (sc *sourceCoordinator) setUpSourceGateway(ctx context.Context, normalizedN
165
156
url , err := srcGate .sourceURL (ctx )
166
157
if err != nil {
167
158
doReturn (nil , err )
168
- return
159
+ return nil , err
169
160
}
170
161
171
162
// We know we have a working srcGateway at this point, and need to
@@ -178,11 +169,12 @@ func (sc *sourceCoordinator) setUpSourceGateway(ctx context.Context, normalizedN
178
169
if sa , has := sc .srcs [url ]; has {
179
170
// URL already had an entry in the main map; use that as the result.
180
171
doReturn (sa , nil )
181
- return
172
+ return sa , nil
182
173
}
183
174
184
175
sc .srcs [url ] = srcGate
185
176
doReturn (srcGate , nil )
177
+ return srcGate , nil
186
178
}
187
179
188
180
// sourceGateways manage all incoming calls for data from sources, serializing
0 commit comments