mirror of
https://github.com/openziti/zrok.git
synced 2025-02-08 22:40:10 +01:00
Ensure loop service listener has started before starting iterate. Log unexpected status codes in loop tool.
This commit is contained in:
parent
deac55be24
commit
5090e61a8f
@ -136,18 +136,19 @@ func (l *looper) run() {
|
|||||||
|
|
||||||
l.startup()
|
l.startup()
|
||||||
logrus.Infof("looper #%d, shrToken: %v, frontend: %v", l.id, l.shrToken, l.proxyEndpoint)
|
logrus.Infof("looper #%d, shrToken: %v, frontend: %v", l.id, l.shrToken, l.proxyEndpoint)
|
||||||
go l.serviceListener()
|
if l.serviceListener() {
|
||||||
l.dwell()
|
l.dwell()
|
||||||
l.iterate()
|
l.iterate()
|
||||||
|
}
|
||||||
logrus.Infof("looper #%d: complete", l.id)
|
logrus.Infof("looper #%d: complete", l.id)
|
||||||
l.shutdown()
|
l.shutdown()
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *looper) serviceListener() {
|
func (l *looper) serviceListener() bool {
|
||||||
zcfg, err := ziti.NewConfigFromFile(l.zif)
|
zcfg, err := ziti.NewConfigFromFile(l.zif)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error opening ziti config '%v': %v", l.zif, err)
|
logrus.Errorf("error opening ziti config '%v': %v", l.zif, err)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
options := ziti.ListenOptions{
|
options := ziti.ListenOptions{
|
||||||
ConnectTimeout: 5 * time.Minute,
|
ConnectTimeout: 5 * time.Minute,
|
||||||
@ -156,15 +157,21 @@ func (l *looper) serviceListener() {
|
|||||||
zctx, err := ziti.NewContext(zcfg)
|
zctx, err := ziti.NewContext(zcfg)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
logrus.Errorf("error loading ziti context: %v", err)
|
logrus.Errorf("error loading ziti context: %v", err)
|
||||||
return
|
return false
|
||||||
}
|
}
|
||||||
if l.listener, err = zctx.ListenWithOptions(l.shrToken, &options); err == nil {
|
|
||||||
|
if l.listener, err = zctx.ListenWithOptions(l.shrToken, &options); err != nil {
|
||||||
|
logrus.Errorf("looper #%d, error listening: %v", l.id, err)
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
go func() {
|
||||||
if err := http.Serve(l.listener, l); err != nil {
|
if err := http.Serve(l.listener, l); err != nil {
|
||||||
logrus.Errorf("looper #%d, error serving: %v", l.id, err)
|
logrus.Errorf("looper #%d, error serving: %v", l.id, err)
|
||||||
}
|
}
|
||||||
} else {
|
}()
|
||||||
logrus.Errorf("looper #%d, error listening: %v", l.id, err)
|
|
||||||
}
|
return true
|
||||||
}
|
}
|
||||||
|
|
||||||
func (l *looper) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
func (l *looper) ServeHTTP(w http.ResponseWriter, r *http.Request) {
|
||||||
@ -239,6 +246,9 @@ func (l *looper) iterate() {
|
|||||||
if req, err := http.NewRequest("POST", l.proxyEndpoint, bytes.NewBufferString(outbase64)); err == nil {
|
if req, err := http.NewRequest("POST", l.proxyEndpoint, bytes.NewBufferString(outbase64)); err == nil {
|
||||||
client := &http.Client{Timeout: time.Second * time.Duration(l.cmd.timeoutSeconds)}
|
client := &http.Client{Timeout: time.Second * time.Duration(l.cmd.timeoutSeconds)}
|
||||||
if resp, err := client.Do(req); err == nil {
|
if resp, err := client.Do(req); err == nil {
|
||||||
|
if resp.StatusCode != 200 {
|
||||||
|
logrus.Errorf("looper #%d unexpected response status code %v!", l.id, resp.StatusCode)
|
||||||
|
}
|
||||||
inpayload := new(bytes.Buffer)
|
inpayload := new(bytes.Buffer)
|
||||||
io.Copy(inpayload, resp.Body)
|
io.Copy(inpayload, resp.Body)
|
||||||
inbase64 := inpayload.String()
|
inbase64 := inpayload.String()
|
||||||
|
Loading…
Reference in New Issue
Block a user