@@ -3,7 +3,6 @@ package container
33import (
44 "context"
55 "fmt"
6- "net"
76 "net/http"
87 "os"
98 stdruntime "runtime"
@@ -14,6 +13,7 @@ import (
1413 "github.com/localstack/lstk/internal/auth"
1514 "github.com/localstack/lstk/internal/config"
1615 "github.com/localstack/lstk/internal/output"
16+ "github.com/localstack/lstk/internal/ports"
1717 "github.com/localstack/lstk/internal/runtime"
1818)
1919
@@ -142,7 +142,7 @@ func selectContainersToStart(ctx context.Context, rt runtime.Runtime, sink outpu
142142 output .EmitLog (sink , fmt .Sprintf ("%s is already running" , c .Name ))
143143 continue
144144 }
145- if err := checkPortAvailable (c .Port ); err != nil {
145+ if err := ports . CheckAvailable (c .Port ); err != nil {
146146 configPath , pathErr := config .ConfigFilePath ()
147147 if pathErr != nil {
148148 return nil , err
@@ -154,18 +154,6 @@ func selectContainersToStart(ctx context.Context, rt runtime.Runtime, sink outpu
154154 return filtered , nil
155155}
156156
157- func checkPortAvailable (port string ) error {
158- conn , err := net .DialTimeout ("tcp" , "localhost:" + port , time .Second )
159- if err != nil {
160- return nil
161- }
162- err = conn .Close ()
163- if err != nil {
164- return nil
165- }
166- return fmt .Errorf ("port %s already in use" , port )
167- }
168-
169157func validateLicense (ctx context.Context , rt runtime.Runtime , sink output.Sink , platformClient api.PlatformAPI , containerConfig runtime.ContainerConfig , token string ) error {
170158 version := containerConfig .Tag
171159 if version == "" || version == "latest" {
0 commit comments