Skip to content

[Bug] new error in socketio #4089

Closed
Closed

Description

@sdetweil

Environment

  • SYSTEM: manufacturer: Apple Inc.; model: Macmini9,1; virtual: false; MM: v2.35.0
  • OS: platform: darwin; distro: macOS; release: 26.4; arch: arm64; kernel: 25.4.0
  • VERSIONS: electron: 41.1.0; used node: 22.21.1; installed node: 22.21.1; npm: 10.9.4; pm2: 6.0.14
  • ENV: XDG_SESSION_TYPE: undefined; MM_CONFIG_FILE: undefined
    WAYLAND_DISPLAY: undefined; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined
  • RAM: total: 16384.00 MB; free: 232.66 MB; used: 16151.34 MB
  • OTHERS: uptime: 809 minutes; timeZone: America/Chicago

Which start option are you using?

node --run start:x11

Are you using PM2?

No

Module

None

Have you tried disabling other modules?

  • Yes
  • No

Have you searched if someone else has already reported the issue on the forum or in the issues?

  • Yes

What did you do?

Configuration

[config.js](https://github.com/user-attachments/files/26481565/config.js)

<!-- Paste relevant code here -->

Steps to reproduce the issue:

in my MMM-Config, I use the same socket.io parent as used by MagicMirror , passed this.io in the node_helper
use like this

socketIOPath = "mConfig"

this.io.of(socketIOPath).on("hello",function(){
  console.log("heard hello from client")
})

What did you expect to happen?

no errors

What actually happened?

get repeating socket.io error, not fatal

[2026-04-04 09:59:36.108] [ERROR] [app] Whoops! There was an uncaught exception...
[2026-04-04 09:59:36.108] [ERROR] [app] TypeError: Cannot read properties of undefined (reading 'hideConfigSecrets')
    at Socket.<anonymous> (/Users/sam/MagicMirror/js/node_helper.js:92:16)
    at Socket.onevent (/Users/sam/MagicMirror/node_modules/socket.io/dist/socket.js:462:26)
    at Socket._onpacket (/Users/sam/MagicMirror/node_modules/socket.io/dist/socket.js:430:22)
    at /Users/sam/MagicMirror/node_modules/socket.io/dist/client.js:207:24
    at process.processTicksAndRejections (node:internal/process/task_queues:85:11)

Additional comments

No response

Participation

  • I am willing to submit a pull request for this change.

Activity

  1. khassel commented on Apr 4, 2026

    @khassel
    Collaborator

    I introduced this with latest release in node_helper.js:

    	setSocketIO (io) {
    		this.io = io;
    
    		Log.log(`Connecting socket for: ${this.name}`);
    
    		io.of(this.name).on("connection", (socket) => {
    			// register catch all.
    			socket.onAny((notification, payload) => {
    				if (config.hideConfigSecrets && payload && typeof payload === "object") {
    					try {
    						const payloadStr = replaceSecretPlaceholder(JSON.stringify(payload));
    						this.socketNotificationReceived(notification, JSON.parse(payloadStr));
    					} catch (e) {
    						Log.error("Error substituting variables in payload: ", e);
    						this.socketNotificationReceived(notification, payload);
    					}
    				} else {
    					this.socketNotificationReceived(notification, payload);
    				}
    			});
    		});
    	}

    But I don't understand your usecase. Maybe config is undefined because hideConfigSecrets is defined in defaults.js.

    Can you test if it works with

    if (config && config.hideConfigSecrets && payload && typeof payload === "object") {

    or

    if global.config.hideConfigSecrets && payload && typeof payload === "object") {

  2. sdetweil commented on Apr 4, 2026

    @sdetweil
    CollaboratorAuthor

    no error with either suggested choice
    my config.js is prior version

  3. khassel commented on Apr 4, 2026

    @khassel
    Collaborator

    but hideConfigSecrets should be merged from defaults.js, can you insert a console.dir(config) before the if statement?

  4. KristjanESPERANTO commented on Apr 4, 2026

    @KristjanESPERANTO
    Collaborator

    One question regarding the MMM-Config module: would it be possible to use the normal MagicMirror API instead of accessing this.io directly?

    socketNotificationReceived(notification, payload)  // to receive
    sendSocketNotification(notification, payload)      // to send

    Accessing this.io is an internal implementation detail and bypasses MM middleware like hideConfigSecrets. Using the public API seems to be cleaner and less likely to break with future MM updates.

  5. sdetweil commented on Apr 4, 2026

    @sdetweil
    CollaboratorAuthor

    Yes, will be a couple hours

  6. sdetweil commented on Apr 4, 2026

    @sdetweil
    CollaboratorAuthor

    @KristjanESPERANTO what is the public socket.io api for using the same port

    io and expressApp are passed to helpers for the purpose of using them on the same setup.

  7. KristjanESPERANTO commented on Apr 4, 2026

    @KristjanESPERANTO
    Collaborator

    Ah, I had a look at the MMM-Config code - yes, my suggestion won't work. The client connecting to the mConfig namespace is an external browser page (form-client.js), not another MagicMirror module. So the normal socketNotificationReceived/sendSocketNotification API isn't an option. Sorry for the noise.

  8. sdetweil commented on Apr 4, 2026

    @sdetweil
    CollaboratorAuthor

    console.log(config) and console.dir(config) both return undefined

    I was wrong earlier..
    if (config && ... works ok

    if(global.config.hideConfigSecrets

    [2026-04-04 12:58:55.206] [INFO]  [updatenotification] Checking git for module: MMM-OnSpotify
    {
      address: 'localhost',
      port: 8080,
      basePath: '/',
      electronOptions: {},
      ipWhitelist: [ '127.0.0.1', '::ffff:127.0.0.1', '::1' ],
      language: 'en',
      logLevel: [ 'INFO', 'LOG', 'WARN', 'ERROR' ],
      timeFormat: 24,
      units: 'metric',
      zoom: 1,
      customCss: 'config/custom.css',
      foreignModulesDir: 'modules',
      defaultModulesDir: 'defaultmodules',
      hideConfigSecrets: false,
      httpHeaders: {
        contentSecurityPolicy: false,
        crossOriginOpenerPolicy: false,
        crossOriginEmbedderPolicy: false,
        crossOriginResourcePolicy: false,
        originAgentCluster: false
      },
      checkServerInterval: 30000,
      reloadAfterServerRestart: false,
      modules: [
        {
          module: 'updatenotification',
          position: 'top_bar',
          order: '*',
          disabled: false,
          hiddenOnStartup: false,
          configDeepMerge: false,
          animateIn: 'None',
          animateOut: 'None'
        },
        {
          module: 'clock',
          position: 'top_left',
          order: '*',
          disabled: false,
          label: 'instance 1',
          hiddenOnStartup: false,
          configDeepMerge: false,
          animateIn: 'None',
          animateOut: 'None',
          index: 0
        },
        {
          module: 'calendar',
          header: 'US Holidays',
          position: 'top_left',
          config: [Object],
          order: '*',
          disabled: false,
          label: 'instance 1',
          hiddenOnStartup: false,
          configDeepMerge: false,
          animateIn: 'None',
          animateOut: 'None',
          index: 0
        },
        {
          module: 'weather',
          position: 'top_right',
          config: [Object],
          order: '*',
          disabled: false,
          label: 'instance 1',
          hiddenOnStartup: false,
          configDeepMerge: false,
          animateIn: 'none',
          animateOut: 'none',
          index: 0
        },
        {
          module: 'weather',
          position: 'top_right',
          header: 'Weather Forecast',
          config: [Object],
          order: '*',
          disabled: false,
          label: 'instance 2',
          hiddenOnStartup: false,
          configDeepMerge: false,
          animateIn: 'none',
          animateOut: 'none',
          index: 1
        },
        {
          module: 'compliments',
          position: 'lower_third',
          order: '*',
          disabled: false,
          label: 'instance 1',
          animateIn: 'None',
          animateOut: 'None',
          index: 0
        },
        {
          module: 'newsfeed',
          position: 'bottom_bar',
          config: {},
          order: '*',
          disabled: false,
          label: 'instance 1',
          hiddenOnStartup: false,
          configDeepMerge: false,
          animateIn: 'None',
          animateOut: 'None',
          index: 0
        },
        {
          module: 'MMM-CalendarExt3',
          position: 'bottom_bar',
          disabled: true,
          title: '',
          config: [Object],
          order: '*',
          label: 'instance 1',
          hiddenOnStartup: false,
          configDeepMerge: false,
          animateIn: 'None',
          animateOut: 'None',
          index: 0
        },
        {
          module: 'MMM-OnSpotify',
          position: 'bottom_right',
          config: [Object],
          order: '*',
          disabled: false,
          hiddenOnStartup: false,
          configDeepMerge: false,
          animateIn: 'None',
          animateOut: 'None'
        },
        {
          module: 'alert',
          order: '*',
          disabled: false,
          label: 'instance 1',
          hiddenOnStartup: false,
          configDeepMerge: false,
          animateIn: 'None',
          animateOut: 'None',
          index: 0
        },
        {
          module: 'MMM-Config',
          poition: 'bottom_right',
          config: {},
          order: '*',
          disabled: false,
          animateIn: 'none',
          animateOut: 'none'
        },
        {
          module: 'MMM-RandomPhoto',
          position: 'fullscreen_below',
          config: [Object]
        },
        {
          module: 'MMM-RandomPhoto',
          position: 'fullscreen_below',
          config: [Object]
        }
      ],
      locale: 'en-US',
      useHttps: false
    }
    [2026-04-04 12:58:55.230] [INFO]  [updatenotification] Checking git for module: MMM-Config
    [2026-04-04 12:58:55.250] [INFO]  [updatenotification] Checking git for module: MMM-RandomPhoto
    [2026-04-04 12:58:55.281] [INFO]  [updatenotification] Checking git for module: MagicMirror
    [2026-04-04 12:58:55.360] [INFO]  [systeminformation] 
    ####  System Information  ####
    - SYSTEM:   manufacturer: Apple Inc.; model: Macmini9,1; virtual: false; MM: v2.35.0
    - OS:       platform: darwin; distro: macOS; release: 26.4; arch: arm64; kernel: 25.4.0
    - VERSIONS: electron: 41.1.0; used node: 22.21.1; installed node: 22.21.1; npm: 10.9.4; pm2: 6.0.14
    - ENV:      XDG_SESSION_TYPE: undefined; MM_CONFIG_FILE: undefined
                WAYLAND_DISPLAY:  undefined; DISPLAY: :0; ELECTRON_ENABLE_GPU: undefined
    - RAM:      total: 16384.00 MB; free: 181.39 MB; used: 16202.61 MB
    - OTHERS:   uptime: 988 minutes; timeZone: America/Chicago
    [2026-04-04 12:58:55.471] [INFO]  [newsfeed] Broadcasting 19 items.
    [2026-04-04 12:58:55.473] [LOG]   [utils] �[0m[�[35mMMM-OnSpotify�[0m] Access token expiration 🗝  >> �[44m�[37m %s �[0m 12:58:55 [Account: 1]
    [2026-04-04 12:58:55.589] [INFO]  [calendar] Broadcasting 10 events from https://ics.calendarlabs.com/76/mm3137/US_Holidays.ics.
    undefined
    [2026-04-04 12:58:55.662] [ERROR] [app] Whoops! There was an uncaught exception...
    [2026-04-04 12:58:55.662] [ERROR] [app] TypeError: Cannot read properties of undefined (reading 'hideConfigSecrets')
        at Socket.<anonymous> (/Users/sam/MagicMirror/js/node_helper.js:94:22)
        at Socket.onevent (/Users/sam/MagicMirror/node_modules/socket.io/dist/socket.js:462:26)
        at Socket._onpacket (/Users/sam/MagicMirror/node_modules/socket.io/dist/socket.js:430:22)
        at /Users/sam/MagicMirror/node_modules/socket.io/dist/client.js:207:24
        at process.processTicksAndRejections (node:internal/process/task_queues:85:11)
    

    and fails every time after the system info section

  9. sdetweil commented on Apr 4, 2026

    @sdetweil
    CollaboratorAuthor

    @KristjanESPERANTO yes, I use socket.io emit() and socket.io.on('submit') etc to move the form data to the browser page and collect the page events and form data back

  10. khassel commented on Apr 4, 2026

    @khassel
    Collaborator

    if (config && ... works ok

    Will you create a pull request to fix this issue, or should I do it?

  11. sdetweil commented on Apr 4, 2026

    @sdetweil
    CollaboratorAuthor

    I will. Might be Monday. Traveling thru tomorrow, and have company now

  12. added 2 commits that reference this issue on Apr 7, 2026
    f09f6ce
    9717d58
  13. KristjanESPERANTO commented on Apr 7, 2026

    @KristjanESPERANTO
    Collaborator

    I've created #4096 to fix this 🙂

  14. added a commit that references this issue on Apr 7, 2026
    d8c29d5
  15. sdetweil commented on Apr 10, 2026

    @sdetweil
    CollaboratorAuthor

    actually I think this fix is wrong as there is still the else clause

    socket.onAny((notification, payload) => {
                                    if (config?.hideConfigSecrets && payload && typeof payload === "object") {
                                            try {
                                                    const payloadStr = replaceSecretPlaceholder(JSON.stringify(payload));
                                                    this.socketNotificationReceived(notification, JSON.parse(payloadStr));
                                            } catch (e) {
                                                    Log.error("Error substituting variables in payload: ", e);
                                                    this.socketNotificationReceived(notification, payload);
                                            }
                                    } else {   <-----
                                            this.socketNotificationReceived(notification, payload); <----
                                    } <---- doesn't apply 
                            });
    

    cause there should be no socketnotification calls on ANY of my socketio calls. and I am not passing notification or payload

    but I only see one notification event.. so I am confused

  16. KristjanESPERANTO commented on Apr 10, 2026

    @KristjanESPERANTO
    Collaborator

    I think the current fix is not wrong; it correctly resolves the reported crash when config is undefined in this path.

    Your new point seems valid and important: which Socket.IO events should be forwarded to socketNotificationReceived at all? Am I understanding this correctly?

    Could these perhaps be possible approaches (I haven't fully thought either of these through yet, so they're for brainstorming):

    • forward only intended/valid notification events, or
    • add an option so modules can opt out of the automatic forwarding behavior.
  17. khassel commented on Apr 10, 2026

    @khassel
    Collaborator

    The line this.socketNotificationReceived(notification, payload); was not introduced with latest release, it was already in this function several releases before ...

  18. sdetweil commented on Apr 10, 2026

    @sdetweil
    CollaboratorAuthor

    Yes, I understand, but I wasn’t aware of this onAny() hook and what it does…

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions