MagicMirrorOrg / MagicMirror

MagicMirror² is an open source modular smart mirror platform. With a growing list of installable modules, the MagicMirror² allows you to convert your hallway or bathroom mirror into your personal assistant.
http://magicmirror.builders
MIT License
19.44k stars 4.15k forks source link

Calendar module: TypeError: fetch failed #3329

Open mattcd216 opened 6 months ago

mattcd216 commented 6 months ago

Platform: pi@magicmirror:~ $ uname -a Linux magicmirror 6.1.21-v7+ #1642 SMP Mon Apr 3 17:20:52 BST 2023 armv7l GNU/Linux pi@magicmirror:~ $ lsb_release -a No LSB modules are available. Distributor ID: Raspbian Description: Raspbian GNU/Linux 11 (bullseye) Release: 11 Codename: bullseye

Node Version: v20.10.0

MagicMirror² Version: v2.26.0

Description: My calendar module does not appear to update at all since the first time it loaded. No events created since the calendar has been added to the module are showing.

Steps to Reproduce:

  1. Add my calendar server & credentials to module config
  2. pm2 restart MagicMirror
  3. View calendar successfully on mirror
  4. Add an event to my calendar which will show within the maximumEntries events
  5. Wait period to allow for fetch interval

Expected Results: I would expect to see the new event I created, especially as I can see events occurring later than my new event.

Actual Results: There is no change to the events shown on the mirror. No new events created are showing. Tried with several new events that are expected to show. The calendar module is still showing events in 3 days time but will not show my newly created event that is scheduled for tomorrow. Errors noted: pi@magicmirror:~/.pm2/logs $ tail --lines=1000 MagicMirror-error.log | grep calendar [02.01.2024 10:29.43.758] [ERROR] Calendar Error. Could not fetch calendar: https://myurl TypeError: fetch failed [02.01.2024 10:31.53.769] [ERROR] Calendar Error. Could not fetch calendar: https://myurl TypeError: fetch failed

Configuration:

{
module: "calendar",
header: "home cloud calendar",
position: "top_left",
config: {
    fetchInterval: 120000,
    timeFormat: 'absolute',
    maximumEntries: 5,
    calendars: [
                 {
            url: 'https://my.locally.hosted.baikal.server.url/dav.php/user/calendar?export',
            auth:   {
                user: 'user',
                pass: 'pass',
                method: 'basic'
                        }
            }
            ],
        }
},

Additional Notes: pm2 restart or a full reboot do not resolve

sdetweil commented 6 months ago

could you do

tail --lines=1000 MagicMirror-error.log | grep -i stack 

to see if there is a stack trace in there

mattcd216 commented 6 months ago

could you do

tail --lines=1000 MagicMirror-error.log | grep -i stack 

to see if there is a stack trace in there

Nothing showing, no

mattcd216 commented 6 months ago

[02.01.2024 14:59.23.139] [ERROR] Calendar Error. Could not fetch calendar: https://my.cal.url TypeError: fetch failed at Object.fetch (node:internal/deps/undici/undici:11576:11) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) { cause: ConnectTimeoutError: Connect Timeout Error at onConnectTimeout (node:internal/deps/undici/undici:8522:28) at node:internal/deps/undici/undici:8480:50 at Immediate._onImmediate (node:internal/deps/undici/undici:8511:13) at process.processImmediate (node:internal/timers:476:21) { code: 'UND_ERR_CONNECT_TIMEOUT' } }

sdetweil commented 6 months ago

so, @rejas @khassel

why didn't the catch on the fetch catch this?


                fetch(url, { headers: headers, agent: httpsAgent })
                        .then(NodeHelper.checkFetchStatus)  // this does a throw if not 200-300
                        .then((response) => response.text())
                        .then((responseData) => {
                                let data = [];

                                try {
                                        data = ical.parseICS(responseData);
                                        Log.debug(`parsed data=${JSON.stringify(data)}`);
                                        events = CalendarFetcherUtils.filterEvents(data, {
                                                excludedEvents,
                                                includePastEvents,
                                                maximumEntries,
                                                maximumNumberOfDays
                                        });
                                } catch (error) {
                                        fetchFailedCallback(this, error);
                                        scheduleTimer();
                                        return;
                                }
                                this.broadcastEvents();
                                scheduleTimer();
                        })
                        .catch((error) => {  //<------here ---------------------------------------------
                                fetchFailedCallback(this, error);
                                scheduleTimer();
                        });
        };
``
or do we need ANOTHER try/catch around it?
Themaster312 commented 6 months ago

Same issue here

sdetweil commented 6 months ago

@Themaster312 try this test code replace lines 58-84 with this

in calendarfetcher.js

        try {

        fetch(url, { headers: headers, agent: httpsAgent })
            .then(NodeHelper.checkFetchStatus)
            .then((response) => response.text())
            .then((responseData) => {
                let data = [];

                try {
                    data = ical.parseICS(responseData);
                    Log.debug(`parsed data=${JSON.stringify(data)}`);
                    events = CalendarFetcherUtils.filterEvents(data, {
                        excludedEvents,
                        includePastEvents,
                        maximumEntries,
                        maximumNumberOfDays
                    });
                } catch (error) {
                    fetchFailedCallback(this, error);
                    scheduleTimer();
                    return;
                }
                this.broadcastEvents();
                scheduleTimer();
            })
            .catch((error) => {
                fetchFailedCallback(this, error);
                scheduleTimer();
            });
        }
        catch(error){
                    console.error( "fetch for calendar url" +url + "failed error="+error.code);
                    fetchFailedCallback(this, error);
                    scheduleTimer();
        }
khassel commented 6 months ago

The fetch call didn't change between v2.25.0 and v2.26.0.

Found this mentioned as workaround but not sure if it is really related.

sdetweil commented 6 months ago

@Pollard-J is this the issue you were looking for?

Pollard-J commented 6 months ago

@sdetweil The issue i had with my calendar was all to do with the Node needing to be updated. which you helped me with. thats all fixed now.

I did just update my MM and it broke it (it wouldn't launch). I updated the pm2 and its fixed it.

sdetweil commented 6 months ago

@Pollard-J thanks for the update.

did u upgrade with my script? or manually ??

sdetweil commented 6 months ago

@Pollard-J

did u upgrade with my script? or manually (git pull && ... ) ??

sdetweil commented 6 months ago

@khassel

but not sure if it is really related

but that seems to be on request() and userAgent() methods, not fetch()..

he did a good upgrade w my script. (from v23 to 26) also upgraded node from 16 to 20.

he has a repeatable failure..

we could get him back to 23 by checking out the tag, and another npm install

khassel commented 6 months ago

so I have no idea to this anymore, only a few users are affected and we don't know why ...

One last thing: Is mm started with npm run server or npm run start?

If they are using electron (npm run start) they are running on the node version provided by electron which is with current release 18.17.1 so upgrading local nodejs is useless.

It would be interesting to see if this problem persists when installing the latest electron version.

sdetweil commented 6 months ago

these are npm run start... using electron..

but he jumped a bunch of releases.. 23-26.

I think the node_helpers are running under command line node.. as electron. loadUrl() hasn't been started yet. as you note electron has its own..

bugsounet commented 6 months ago

Hi, I have 2 users with same problem callback is not sended and break some others modules

sample:

[04.01.2024 22:51.37.799] [ERROR] Calendar Error. Could not fetch calendar: https://calendar.google.com/calendar/ical/xxxxgmail.com/private-xxxxxxxxx/basic.ics TypeError: fetch failed
at Object.fetch (node:internal/deps/undici/undici:11576:11) {
cause: SocketError: other side closed
at TLSSocket.onSocketEnd (node:internal/deps/undici/undici:9790:26)
at TLSSocket.emit (node:events:526:35)
at endReadableNT (node:internal/streams/readable:1359:12)
at process.processTicksAndRejections (node:internal/process/task_queues:82:21) {
code: ‘UND_ERR_SOCKET’,
socket: {
localAddress: ‘2a01:e0a:24:1790:2ca6:1585:d270:49fb’,
localPort: 58746,
remoteAddress: undefined,
remotePort: undefined,
remoteFamily: undefined,
timeout: undefined,
bytesWritten: 754,
bytesRead: 96273
}
}
}
sdetweil commented 6 months ago

that's different. other side closed.

but it's using the ipv6 address. have them turn off the v6 address. dont need it at home

bugsounet commented 6 months ago

yes but callback is not sended too

sdetweil commented 6 months ago

what callback,? you mean the .then() Promise resolve?

GaryCooper23 commented 6 months ago

sudo nano /etc/sysctl.conf

# Disable IPv6 net.ipv6.conf.all.disable_ipv6 = 1 net.ipv6.conf.default.disable_ipv6 = 1 net.ipv6.conf.lo.disable_ipv6 = 1

sudo nano /etc/sysctl.conf

Solved it for now. Please implement a better solution.

sdetweil commented 6 months ago

@GaryCooper23 thanks for the feedback. the problem is not in our code. but in the node js engine. we will have to wait for a fix.

but you don't need ip 6 on your local network, as you only have a few devices.

khassel commented 6 months ago

Maybe the problems are caused by the node version (18.17.1) in the used electron version (27.2.0).

There were fixes for autoSelectFamily with node version 18.18.0.

The latest electron release 28.1.1 contains the node version 18.18.2, so contains the above fixes.

It would be helpful for us if someone with this problem could test if it still persists when using electron 28.1.1.

sdetweil commented 6 months ago

ok will see

sdetweil commented 5 months ago

one feedback that 28.1.1 solved problem

z-master42 commented 4 months ago

I also have the problem that the calendar module no longer loads anything.

I have installed electron 28.2.1. But nothing has changed.

Even if the address where the calendar is located is not accessible, no error appears in the log. On the MagicMirror the calendar module is loading all the time.

sdetweil commented 4 months ago

@z-master42 install the old parser

cd ~/MagicMirror
npm install node-ical@0.16.1

restart MagicMirror

z-master42 commented 4 months ago

node-ical is on 0.16.1. No change so far.

khassel commented 3 days ago

is this still an issue with latest MagicMirror Release v2.28.0?

Background: In the new release we are using electron v31 which internally uses node v20 (instead of v18 before).