mirror of
https://github.com/MHSanaei/3x-ui.git
synced 2026-10-24 23:05:01 +03:00
d2a0216e01
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.
45 lines
1.0 KiB
Go
45 lines
1.0 KiB
Go
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()
|
|
}
|