mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-11-02 11:15:03 +03:00
fix(web): install the share-link provider before the panel serves (#6914)
The panel started answering requests before the share-link generator was registered, so an "all links", client sub-links or Telegram link request that arrived during start-up got "sub link provider not registered". NewServer now takes the provider and installs it before anything listens, and the provider registry is guarded by a lock, since start-up writes it while requests read it.
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
package service
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
|
||||
"github.com/mhsanaei/3x-ui/v3/internal/database/model"
|
||||
)
|
||||
|
||||
type fakeSubLinkProvider struct {
|
||||
links []string
|
||||
}
|
||||
|
||||
func (f fakeSubLinkProvider) SubLinksForSubId(host, subId string) ([]string, error) {
|
||||
return f.links, nil
|
||||
}
|
||||
|
||||
func (f fakeSubLinkProvider) LinksForClient(host string, inbound *model.Inbound, email string) []string {
|
||||
return f.links
|
||||
}
|
||||
|
||||
func (f fakeSubLinkProvider) LinksForInbounds(host string, inbounds []*model.Inbound) []string {
|
||||
return f.links
|
||||
}
|
||||
|
||||
// Startup writes the provider registry while link requests read it; under -race an
|
||||
// unguarded registry fails here.
|
||||
func TestSubLinkProviderRegistrationIsRaceFree(t *testing.T) {
|
||||
t.Cleanup(func() { RegisterSubLinkProvider(nil) })
|
||||
|
||||
var wg sync.WaitGroup
|
||||
for range 8 {
|
||||
wg.Add(2)
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
RegisterSubLinkProvider(fakeSubLinkProvider{links: []string{"vless://example"}})
|
||||
}()
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
_, _ = (&InboundService{}).GetSubLinks("panel.example", "subid")
|
||||
}()
|
||||
}
|
||||
wg.Wait()
|
||||
}
|
||||
Reference in New Issue
Block a user