steilerDev / homebridge-openhab2-complete

A homebridge plugin for openHAB, that has the expectation to fully support all Services offered by Apple's Homekit Accessory Protocol (HAP)
GNU General Public License v3.0
52 stars 16 forks source link

Homebridge crashes when openHAB is not available for connection #71

Closed sonntam closed 4 years ago

sonntam commented 4 years ago

Describe the bug When openHAB2 is not available e.g. after reboot, homebridge crashes with an unhandled ECONNREFUSED exception within the isOnline() function (see log below).

Expected behavior homebridge-openhab2-complete should wait until openHAB2 is available instead of crashing homebridge.

Configurations

{
    "bridge": {
        "name": "Homebridge",
        "username": "CB:22:3D:E2:CE:31",
        "port": 51826,
        "pin": "033-44-254"
    },
    "accessories": [],
    "platforms": [
        {
            "name": "Config",
            "port": 8081,
            "auth": "form",
            "theme": "dark-mode",
            "restart": "sudo -n systemctl restart homebridge",
            "tempUnits": "c",
            "sudo": true,
            "log": {
                "method": "systemd"
            },
            "platform": "config"
        },
        {
            "platform": "openHAB2-Complete",
            "host": "http://raspberrypi4.fritz.box",
            "port": "8080",
            "accessories": [
                {
                    "name": "Beleuchtung Bücherregal",
                    "type": "light",
                    "item": "MQTTSonoff_BeleuchtungBCherregal"
                },
                {
                    "name": "Beleuchtung Fernseher",
                    "type": "light",
                    "item": "MQTTSonoff_BeleuchtungTV"
                },
                {
                    "name": "3D-Drucker",
                    "type": "outlet",
                    "item": "ghoma_3dprinter"
                },
                {
                    "name": "Vitrine",
                    "type": "outlet",
                    "item": "ghoma_vitrine"
                }
            ]
        }
    ]
}

Logs:

Feb 06 18:45:59 raspberrypi homebridge[2371]: [06/02/2020, 18:45:59] [openHAB2-Complete] Waiting for openHAB host (http://raspberrypi4.fritz.box) to come onl                                                                                ine...
Feb 06 18:46:03 raspberrypi homebridge[2371]: [06/02/2020, 18:46:03] [Config] Homebridge Config UI X v4.9.0 is listening on :: port 8081
Feb 06 18:46:05 raspberrypi homebridge[2371]: [06/02/2020, 18:46:05] Error: connect ECONNREFUSED 192.168.0.35:8080
Feb 06 18:46:05 raspberrypi homebridge[2371]:     at extractValue (/usr/lib/node_modules/homebridge-openhab2-complete/node_modules/sync-rpc/lib/index.js:165:                                                                                19)
Feb 06 18:46:05 raspberrypi homebridge[2371]:     at /usr/lib/node_modules/homebridge-openhab2-complete/node_modules/sync-rpc/lib/index.js:175:12
Feb 06 18:46:05 raspberrypi homebridge[2371]:     at request (/usr/lib/node_modules/homebridge-openhab2-complete/node_modules/sync-request/lib/index.js:28:15                                                                                )
Feb 06 18:46:05 raspberrypi homebridge[2371]:     at OpenHAB.isOnline (/usr/lib/node_modules/homebridge-openhab2-complete/util/OpenHAB.js:68:27)
Feb 06 18:46:05 raspberrypi homebridge[2371]:     at new OpenHABComplete (/usr/lib/node_modules/homebridge-openhab2-complete/index.js:80:45)
Feb 06 18:46:05 raspberrypi homebridge[2371]:     at Server._loadPlatforms (/usr/lib/node_modules/homebridge/lib/server.js:337:32)
Feb 06 18:46:05 raspberrypi homebridge[2371]:     at Server.run (/usr/lib/node_modules/homebridge/lib/server.js:90:36)
Feb 06 18:46:05 raspberrypi homebridge[2371]:     at module.exports (/usr/lib/node_modules/homebridge/lib/cli.js:59:10)
Feb 06 18:46:05 raspberrypi homebridge[2371]:     at Object.<anonymous> (/usr/lib/node_modules/homebridge/bin/homebridge:17:22)
Feb 06 18:46:05 raspberrypi homebridge[2371]:     at Module._compile (internal/modules/cjs/loader.js:1151:30)
Feb 06 18:46:05 raspberrypi homebridge[2371]: [06/02/2020, 18:46:05] Got SIGTERM, shutting down Homebridge...
Feb 06 18:46:10 raspberrypi systemd[1]: homebridge.service: Main process exited, code=exited, status=143/n/a
Feb 06 18:46:10 raspberrypi systemd[1]: homebridge.service: Failed with result 'exit-code'.

Environment (please complete the following information):

Additional context The issue #63 may be related to this as it often seems to occur after a hard crash of homebridge.

sonntam commented 4 years ago

I'm preparing a pull request for this issue. My solution simply is to handle the exception correctly.