Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Infinite loop when registering a service and listening at the same time #22

Closed
fdulger opened this issue Nov 15, 2023 · 1 comment
Closed

Comments

@fdulger
Copy link

fdulger commented Nov 15, 2023

In my specific use case I need to both listen mdns packages of my devices in the network and at the same time announce my application to the network. When I do this:

import net.posick.mdns.*
import org.xbill.DNS.Message
import org.xbill.DNS.Name

fun main() {

    val mDNSService = MulticastDNSService()

    val deviceListener = object : DNSSDListener {
        override fun serviceDiscovered(id: Any, service: ServiceInstance) {
            println("serviceDiscovered $service")
        }

        override fun serviceRemoved(id: Any, service: ServiceInstance) {
            println("serviceRemoved $service")
        }

        override fun receiveMessage(id: Any, m: Message) {
            println("receiveMessage $m")
        }

        override fun handleException(id: Any, ex: Exception) {
            ex.printStackTrace()
        }
    }

    val service = ServiceInstance(
        ServiceName("myservice._http._tcp.local."),
        0,
        0,
        8443,
        Name.fromString("myservice._http._tcp.local."),
    )

    mDNSService.startServiceDiscovery(Browse("_device-id._tcp.local."), deviceListener)

    println("Announcing my service $service")
    mDNSService.register(service)
}

I am getting a StackOverflowError

Announcing my service Service ("myservice._http._tcp.local." can be reached at "myservice._http._tcp.local." [---] on port 8443)
Exception in thread "main" java.lang.StackOverflowError
	at java.base/jdk.internal.reflect.Reflection.verifyMemberAccess(Reflection.java:141)
	at java.base/java.lang.reflect.AccessibleObject.slowVerifyAccess(AccessibleObject.java:715)
	at java.base/java.lang.reflect.AccessibleObject.verifyAccess(AccessibleObject.java:701)
	at java.base/java.lang.reflect.AccessibleObject.checkAccess(AccessibleObject.java:673)
	at java.base/java.lang.reflect.Method.invoke(Method.java:560)
	at org.xbill.DNS.MulticastDNSUtils.getTargetFromRecord(MulticastDNSUtils.java:219)
	at net.posick.mdns.MulticastDNSCache.queryCacheForAdditionalRecords(MulticastDNSCache.java:331)
	at net.posick.mdns.MulticastDNSCache.queryCacheForAdditionalRecords(MulticastDNSCache.java:338)
	at net.posick.mdns.MulticastDNSCache.queryCacheForAdditionalRecords(MulticastDNSCache.java:338)
	at net.posick.mdns.MulticastDNSCache.queryCacheForAdditionalRecords(MulticastDNSCache.java:338)
	...

What am I doing wrong here?

@fdulger
Copy link
Author

fdulger commented Nov 16, 2023

In case anyone else bumps into a similar issue, this seems to be gone when I change my service to this:

val service = ServiceInstance(
        ServiceName("myservice._http._tcp.local."),
        0,
        0,
        8443,
        Name.fromString("myservice."), // instead of "myservice._http._tcp.local."
    )

@fdulger fdulger closed this as completed Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant