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

Calendar module: TypeError: fetch failed #3329

Open
mattcd216 opened this issue Jan 2, 2024 · 26 comments
Open

Calendar module: TypeError: fetch failed #3329

mattcd216 opened this issue Jan 2, 2024 · 26 comments
Labels

Comments

@mattcd216
Copy link

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
Copy link
Collaborator

sdetweil commented Jan 2, 2024

could you do

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

to see if there is a stack trace in there

@mattcd216
Copy link
Author

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
Copy link
Author

[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
Copy link
Collaborator

sdetweil commented Jan 2, 2024

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
Copy link

Same issue here

@sdetweil
Copy link
Collaborator

sdetweil commented Jan 2, 2024

@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
Copy link
Collaborator

khassel commented Jan 2, 2024

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
Copy link
Collaborator

sdetweil commented Jan 2, 2024

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

@Pollard-J
Copy link

@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
Copy link
Collaborator

sdetweil commented Jan 2, 2024

@Pollard-J thanks for the update.

did u upgrade with my script? or manually ??

@sdetweil
Copy link
Collaborator

sdetweil commented Jan 3, 2024

@Pollard-J

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

@sdetweil
Copy link
Collaborator

sdetweil commented Jan 3, 2024

@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
Copy link
Collaborator

khassel commented Jan 3, 2024

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
Copy link
Collaborator

sdetweil commented Jan 3, 2024

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
Copy link
Contributor

bugsounet commented Jan 4, 2024

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
Copy link
Collaborator

sdetweil commented Jan 4, 2024

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
Copy link
Contributor

yes but callback is not sended too

@sdetweil
Copy link
Collaborator

sdetweil commented Jan 5, 2024

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

@GaryCooper23
Copy link

GaryCooper23 commented Jan 6, 2024

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
Copy link
Collaborator

sdetweil commented Jan 6, 2024

@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
Copy link
Collaborator

khassel commented Jan 6, 2024

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
Copy link
Collaborator

sdetweil commented Jan 6, 2024

ok will see

@sdetweil
Copy link
Collaborator

sdetweil commented Jan 9, 2024

one feedback that 28.1.1 solved problem

@z-master42
Copy link

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
Copy link
Collaborator

sdetweil commented Feb 6, 2024

@z-master42 install the old parser

cd ~/MagicMirror
npm install [email protected]

restart MagicMirror

@z-master42
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

8 participants