(ctx context.Context)
| 120 | } |
| 121 | |
| 122 | func (s *Server) StartProxy(ctx context.Context) error { |
| 123 | ctx, stopfn := context.WithCancel(ctx) |
| 124 | |
| 125 | lock := flock.New(filepath.Join(s.RootDir, lockfile)) |
| 126 | if err := lock.Lock(); err != nil { |
| 127 | stopfn() |
| 128 | return err |
| 129 | } |
| 130 | |
| 131 | addrRails, waitRails, err := s.startRails(ctx) |
| 132 | if err != nil { |
| 133 | _ = lock.Unlock() |
| 134 | stopfn() |
| 135 | return err |
| 136 | } |
| 137 | |
| 138 | host, port, err := net.SplitHostPort(addrRails) |
| 139 | if err != nil { |
| 140 | stopfn() |
| 141 | return err |
| 142 | } |
| 143 | s.RailsPort = port |
| 144 | |
| 145 | if s.Host != "" { |
| 146 | host = s.Host |
| 147 | } |
| 148 | |
| 149 | addr, waitPrism, err := s.startProxy(ctx, host+":"+port) |
| 150 | if err != nil { |
| 151 | _ = lock.Unlock() |
| 152 | stopfn() |
| 153 | return err |
| 154 | } |
| 155 | |
| 156 | group := new(errgroup.Group) |
| 157 | |
| 158 | group.Go(func() error { return s.waitTCP(addr) }) |
| 159 | group.Go(func() error { return s.waitTCP(addrRails) }) |
| 160 | |
| 161 | if err := group.Wait(); err != nil { |
| 162 | _ = lock.Unlock() |
| 163 | stopfn() |
| 164 | return err |
| 165 | } |
| 166 | |
| 167 | group = new(errgroup.Group) |
| 168 | |
| 169 | group.Go(waitPrism) |
| 170 | group.Go(waitRails) |
| 171 | |
| 172 | host, port, err = net.SplitHostPort(addr) |
| 173 | if err != nil { |
| 174 | stopfn() |
| 175 | return err |
| 176 | } |
| 177 | |
| 178 | if s.Host != "" { |
| 179 | host = s.Host |
no test coverage detected