|
5 | 5 | "regexp" |
6 | 6 | "strconv" |
7 | 7 | "strings" |
| 8 | + "sync/atomic" |
8 | 9 |
|
9 | 10 | "mjpclab.dev/ghfs/src/middleware" |
10 | 11 | "mjpclab.dev/ghfs/src/param" |
@@ -49,7 +50,8 @@ type aliasHandler struct { |
49 | 50 | archive *hierarchyAvailability |
50 | 51 | cors *hierarchyAvailability |
51 | 52 |
|
52 | | - archiveWorkers chan struct{} |
| 53 | + archiveMaxWorkers int32 |
| 54 | + archiveWorkers *int32 |
53 | 55 |
|
54 | 56 | globalRestrictAccess []string |
55 | 57 | restrictAccessUrls pathStringsList |
@@ -143,11 +145,11 @@ func (h *aliasHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) { |
143 | 145 | } |
144 | 146 |
|
145 | 147 | func (h *aliasHandler) createArchive(w http.ResponseWriter, r *http.Request, session *sessionContext, data *responseData) bool { |
146 | | - if h.archiveWorkers != nil { |
147 | | - select { |
148 | | - case h.archiveWorkers <- struct{}{}: |
149 | | - defer func() { <-h.archiveWorkers }() |
150 | | - default: |
| 148 | + if h.archiveMaxWorkers > 0 { |
| 149 | + current := atomic.AddInt32(h.archiveWorkers, -1) |
| 150 | + defer atomic.AddInt32(h.archiveWorkers, 1) |
| 151 | + |
| 152 | + if current < 0 { |
151 | 153 | data.Status = http.StatusTooManyRequests |
152 | 154 | return false |
153 | 155 | } |
@@ -192,7 +194,8 @@ func newAliasHandler( |
192 | 194 | toHttpsPort: p.ToHttpsPort, |
193 | 195 | defaultSort: p.DefaultSort, |
194 | 196 |
|
195 | | - archiveWorkers: p.ArchivationsSem, |
| 197 | + archiveMaxWorkers: vhostCtx.archiveMaxWorkers, |
| 198 | + archiveWorkers: vhostCtx.archiveWorkers, |
196 | 199 |
|
197 | 200 | users: vhostCtx.users, |
198 | 201 | theme: vhostCtx.theme, |
|
0 commit comments