brutella / hap

The HomeKit Accessory Protocol (hap) implemented in Go
Apache License 2.0
346 stars 39 forks source link

Build window fail #2

Open zuozhehao opened 2 years ago

zuozhehao commented 2 years ago
goroutine 18 [running]:
github.com/brutella/dnssd.(*Service).IPsAtInterface(0xc0000736b8, 0x0)
        D:/***/github.com/brutella/dnssd@v1.2.2/service.go:150 +0x3d
github.com/brutella/dnssd.A({{0xc000212020, 0x4}, {0x6d4654, 0x9}, {0x6d3039, 0x5}, {0xc000212024, 0xc}, 0xc000206120, 0x0, ...}, ...)
        D:/***/github.com/brutella/dnssd@v1.2.2/dns.go:116 +0x39
github.com/brutella/dnssd.containsConflictingAnswers(0xc000406090, 0xc000214020)
        D:/***/github.com/brutella/dnssd@v1.2.2/responder.go:465 +0xbb
github.com/brutella/dnssd.findConflicts(0xc000406090, {0xc00040a010, 0x1, 0x1?})
        D:/***/github.com/brutella/dnssd@v1.2.2/responder.go:446 +0x9b
github.com/brutella/dnssd.(*responder).handleRequest(0xc000210000, 0xc000406090)
        D:/***/github.com/brutella/dnssd@v1.2.2/responder.go:238 +0x195
github.com/brutella/dnssd.(*responder).respond(0xc000210000, {0x775710, 0xc00022c040})
        D:/***/github.com/brutella/dnssd@v1.2.2/responder.go:203 +0x1d4
github.com/brutella/dnssd.(*responder).Respond(0xc000210000, {0x775710, 0xc00022c040})
        D:/***/github.com/brutella/dnssd@v1.2.2/responder.go:113 +0x3ef
github.com/brutella/hap.(*Server).listenAndServe.func1()
        D:/***/github.com/brutella/hap@v0.0.14/server.go:205 +0x37
created by github.com/brutella/hap.(*Server).listenAndServe
        D:/***/github.com/brutella/hap@v0.0.14/server.go:204 +0x465

Process finished with the exit code 2

Same question https://github.com/brutella/hc/issues/201

brutella commented 2 years ago

I'm still confused on why s.ifaceIPs is nil only on Windows? Doesn't make any sense!

zuozhehao commented 2 years ago

I'm still confused on why s.ifaceIPs is nil only on Windows? Doesn't make any sense!

I haven't added any code yet, just use the example code

package main

import (
    "github.com/brutella/hap"
    "github.com/brutella/hap/accessory"

    "context"
    "log"
    "os"
    "os/signal"
    "syscall"
)

func main() {
    // Create the switch accessory.
    a := accessory.NewSwitch(accessory.Info{
        Name: "Lamp",
    })

    // Store the data in the "./db" directory.
    fs := hap.NewFsStore("./db")

    // Create the hap server.
    server, err := hap.NewServer(fs, a.A)
    if err != nil {
        // stop if an error happens
        log.Panic(err)
    }

    // Setup a listener for interrupts and SIGTERM signals
    // to stop the server.
    c := make(chan os.Signal)
    signal.Notify(c, os.Interrupt)
    signal.Notify(c, syscall.SIGTERM)

    ctx, cancel := context.WithCancel(context.Background())
    go func() {
        <-c
        // Stop delivering signals.
        signal.Stop(c)
        // Cancel the context to stop the server.
        cancel() 
    }()

    // Run the server.
    server.ListenAndServe(ctx)
}
hepeichun commented 2 years ago

I'm still confused on why s.ifaceIPs is nil only on Windows? Doesn't make any sense!

I haven't added any code yet, just use the example code

package main

import (
  "github.com/brutella/hap"
  "github.com/brutella/hap/accessory"

  "context"
  "log"
  "os"
  "os/signal"
  "syscall"
)

func main() {
  // Create the switch accessory.
  a := accessory.NewSwitch(accessory.Info{
      Name: "Lamp",
  })

  // Store the data in the "./db" directory.
  fs := hap.NewFsStore("./db")

  // Create the hap server.
  server, err := hap.NewServer(fs, a.A)
  if err != nil {
      // stop if an error happens
      log.Panic(err)
  }

  // Setup a listener for interrupts and SIGTERM signals
  // to stop the server.
  c := make(chan os.Signal)
  signal.Notify(c, os.Interrupt)
  signal.Notify(c, syscall.SIGTERM)

  ctx, cancel := context.WithCancel(context.Background())
  go func() {
      <-c
      // Stop delivering signals.
      signal.Stop(c)
      // Cancel the context to stop the server.
      cancel() 
  }()

  // Run the server.
  server.ListenAndServe(ctx)
}

@brutella @zuozhehao This might have something to do with IPv6.

zuozhehao commented 2 years ago

https://github.com/brutella/dnssd/blob/master/mdns.go#L146

image

I think it should be caused here.


https://github.com/brutella/dnssd/blob/master/mdns.go#L220

it's error message read udp4 0.0.0.0:5353: use of closed network connection

@brutella