MagicMirror icon indicating copy to clipboard operation
MagicMirror copied to clipboard

Calendar module: TypeError: fetch failed

Open mattcd216 opened this issue 1 year ago • 26 comments

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

mattcd216 avatar Jan 02 '24 14:01 mattcd216

could you do

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

to see if there is a stack trace in there

sdetweil avatar Jan 02 '24 14:01 sdetweil

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 avatar Jan 02 '24 14:01 mattcd216

[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' } }

mattcd216 avatar Jan 02 '24 16:01 mattcd216

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?

sdetweil avatar Jan 02 '24 16:01 sdetweil

Same issue here

Themaster312 avatar Jan 02 '24 17:01 Themaster312

@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();
		}

sdetweil avatar Jan 02 '24 17:01 sdetweil

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.

khassel avatar Jan 02 '24 19:01 khassel

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

sdetweil avatar Jan 02 '24 21:01 sdetweil

@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.

Pollard-J avatar Jan 02 '24 22:01 Pollard-J

@Pollard-J thanks for the update.

did u upgrade with my script? or manually ??

sdetweil avatar Jan 02 '24 22:01 sdetweil

@Pollard-J

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

sdetweil avatar Jan 03 '24 15:01 sdetweil

@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

sdetweil avatar Jan 03 '24 23:01 sdetweil

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.

khassel avatar Jan 03 '24 23:01 khassel

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..

sdetweil avatar Jan 03 '24 23:01 sdetweil

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
}
}
}

bugsounet avatar Jan 04 '24 22:01 bugsounet

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

sdetweil avatar Jan 04 '24 22:01 sdetweil

yes but callback is not sended too

bugsounet avatar Jan 04 '24 22:01 bugsounet

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

sdetweil avatar Jan 05 '24 01:01 sdetweil

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.

GaryCooper23 avatar Jan 06 '24 11:01 GaryCooper23

@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.

sdetweil avatar Jan 06 '24 13:01 sdetweil

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.

khassel avatar Jan 06 '24 21:01 khassel

ok will see

sdetweil avatar Jan 06 '24 21:01 sdetweil

one feedback that 28.1.1 solved problem

sdetweil avatar Jan 09 '24 13:01 sdetweil

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.

z-master42 avatar Feb 06 '24 19:02 z-master42

@z-master42 install the old parser

cd ~/MagicMirror
npm install [email protected]

restart MagicMirror

sdetweil avatar Feb 06 '24 20:02 sdetweil

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

z-master42 avatar Feb 06 '24 21:02 z-master42

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).

khassel avatar Jul 01 '24 22:07 khassel

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).

Seems to be. Just did a fresh install using the docker image provided by karsten13/magicmirror:fat which lists v2.28.0 as the version used. Exact same error for the newsfeed module (obviously referncing newsfeed: https://rss.nytimes.com/services/xml/rss/nyt/HomePage.xml though)

[2024-07-15 07:27:48.330] [ERROR] Calendar Error. Could not fetch calendar:  https://ics.calendarlabs.com/76/mm3137/US_Holidays.ics TypeError: fetch failed
at node:internal/deps/undici/undici:12502:13
at processTicksAndRejections (node:internal/process/task_queues:95:5)
at runNextTicks (node:internal/process/task_queues:64:3)
at process.processImmediate (node:internal/timers:449:9) {
[cause]: ConnectTimeoutError: Connect Timeout Error
at onConnectTimeout (node:internal/deps/undici/undici:6635:28)
at node:internal/deps/undici/undici:6587:50
at Immediate._onImmediate (node:internal/deps/undici/undici:6619:13)
at process.processImmediate (node:internal/timers:478:21) {
code: 'UND_ERR_CONNECT_TIMEOUT'
}
}

EDIT:

N/m this. seems to be something with the docker container only. spun up a virtual machine and followed the install steps on https://docs.magicmirror.builders/getting-started/installation.html#manual-installation and have no issues like this anymore

k0b4lt avatar Jul 15 '24 11:07 k0b4lt

Everything works for me. From my point of view, this issue can be closed.

z-master42 avatar Jul 15 '24 17:07 z-master42

N/m this. seems to be something with the docker container only. spun up a virtual machine and followed the install steps on https://docs.magicmirror.builders/getting-started/installation.html#manual-installation and have no issues like this anymore

can you share the used docker-compose.yml file?

khassel avatar Jul 15 '24 17:07 khassel