Page MenuHomePhabricator

TypeError: Cannot read properties of undefined (reading 'operator')
Closed, ResolvedPublicBUG REPORT

Description

Steps to replicate the issue (include links if applicable):

  • Import data for ipoid using November 10
  • Run main.sh --updatedb

What happens?:

Update init already run, skipping...
Update remove-tunnel-anonymous-property already run, skipping...
Database updated!
Feed for 20231111 exists, pulling now...
Feed downloaded to /tmp/20231111.json.gz
Feed for 20231110 exists, pulling now...
Feed downloaded to /tmp/20231110.json.gz
Removing potential stale files...
Unzipping yesterday's file...
Sorting yesterday's file...
Unzipping today's file...
Aggregating today's properties...
Sorting today's file...
Finding lines unique to old file...
Finding lines unique to new file...
Processing unique files...
Joining and sorting unique files...
Outputting SQL statements...
/srv/service/output-sql.js:39
                        if ( tunnel1.operator !== tunnel2.operator ) {
                                                          ^

TypeError: Cannot read properties of undefined (reading 'operator')
    at tunnelsCompare (/srv/service/output-sql.js:39:38)
    at tunnelsArrayCompare (/srv/service/output-sql.js:65:11)
    at checkIfChanged (/srv/service/output-sql.js:147:11)
    at Interface.diff (/srv/service/output-sql.js:335:11)
    at Interface.emit (node:events:513:28)
    at Interface._onLine (node:readline:491:10)
    at Interface._normalWrite (node:readline:665:12)
    at ReadStream.ondata (node:readline:272:10)
    at ReadStream.emit (node:events:513:28)
    at ReadStream.Readable.read (node:internal/streams/readable:527:10)

What should have happened instead?:

no error.

Software version (skip for WMF-hosted wikis like Wikipedia):

Other information (browser name/version, screenshots, etc.):

QA Results - ipoid- vsc

Details

Related Changes in Gerrit:
Related Changes in GitLab:
TitleReferenceAuthorSource BranchDest Branch
output-sql.js: Fix tunnels arrays comparisonrepos/mediawiki/services/ipoid!181kharlanmain-Ia25675cf80feba9f6cc1824f9db76e36e85d5b6amain
Customize query in GitLab

Event Timeline

Change 974497 had a related patch set uploaded (by Kosta Harlan; author: Kosta Harlan):

[operations/deployment-charts@master] ipoid: Bump version

https://gerrit.wikimedia.org/r/974497

Change 974497 merged by jenkins-bot:

[operations/deployment-charts@master] ipoid: Bump version

https://gerrit.wikimedia.org/r/974497

Dreamy_Jazz added subscribers: Tchanders, Dreamy_Jazz.

(Assigning @Tchanders to this task based on the associated patch)

dom_walden subscribed.

I can no longer reproduce the error from the description.

In my previous testing, I had missed this bug because I hadn't appreciated that the diff algorithm compares one field at a time and returns early as soon as it finds one that is different. Fields that are compared earlier in the code were better tested than fields that are compared later. Therefore, while testing this, I made sure that I only changed one field at a time for each IP. I also generated data randomly rather than relying on real data,

It occurred to me that it might be easier to test this at the unit level, at least from the perspective of cognitive complexity of generating test data. I experimented with unit testing the individual functions in output-sql.js using random data generators. It is certainly possible to trigger other exceptions (some I have raised as bugs), especially if you allow the random generator to produce any kind of data it wants.

Other exceptions
I haven't raised any of the below as bugs yet. I don't know how defensive we want to be.

If you pass something that isn't a list to tunnelsArrayCompare (either directly to the function or through checkIfChanged):

TypeError: arr1.sort is not a function

If the list of tunnels contains something that isn't a dictionary in checkIfChanged:

TypeError: Cannot create property 'type' on string 'i%~pKE]`'
    at /srv/service/import-data-utils.js:101:16
    at Array.forEach (<anonymous>)
    at getTunnels (/srv/service/import-data-utils.js:99:10)

If you pass undefined or null to tunnelsCompare or tunnelsSort:

TypeError: Cannot read properties of undefined (reading 'operator')

(Obviously!)

Code

@Tchanders does this task need moving to the next sprint or can this be marked as resolved?

@Tchanders I received a type error: : Cannot read properties of undefined (reading 'count') after running diff.sh using the test data that was used previously.

Status: ❌Fail
Environment: VSC
OS: macOS Sonoma 14.2
Browser: N/A
Skins. N/A
Device: MBA M2
Emulated Device:: n/a
Test Links:
N/A

❌AC1: https://phabricator.wikimedia.org/T351197

Code for generating test input data: https://gitlab.wikimedia.org/dwalden/ipmasking-testing/-/blob/main/spur_random_data_valid_1.py

Steps

  • python3 tmp/spur_random_data_valid_1.py > randomtest.json
  • gzip -c randomtest.json > randomtest2.json.g
  • docker-compose exec web ./diff.sh --today tmp/randomtest2.json.gz

2024-01-09_11-07-52.png (466×1 px, 102 KB)

TypeError: Cannot read properties of undefined (reading 'count')
    at generateInsertActorQueries (/srv/service/output-sql.js:174:33)
    at Interface.import (/srv/service/output-sql.js:363:6)
    at Interface.emit (node:events:513:28)
    at Interface._onLine (node:readline:491:10)
    at Interface._normalWrite (node:readline:665:12)
    at ReadStream.ondata (node:readline:272:10)
    at ReadStream.emit (node:events:513:28)
    at addChunk (node:internal/streams/readable:315:12)
    at readableAddChunk (node:internal/streams/readable:289:9)
    at ReadStream.Readable.push (node:internal/streams/readable:228:10)

Change 989503 had a related patch set uploaded (by Kosta Harlan; author: Kosta Harlan):

[operations/deployment-charts@master] ipoid: Bump version

https://gerrit.wikimedia.org/r/989503

Change 989503 merged by jenkins-bot:

[operations/deployment-charts@master] ipoid: Bump version

https://gerrit.wikimedia.org/r/989503

@Tchanders I'm not sure if the reloaded patch was supposed to resolve but I'm still getting the same issue as previously when running those steps.

commit 47078469e00116422a82cca8c0b4770e4a8a12d3
Thu Jan 18 11:37:45 2024

2024-01-18_09-08-16.png (522×2 px, 152 KB)

Note that while testing this on the latest version of ipoid, I noticed that spur_random_data_valid_1.py creates data that does not have valid IPv4/6 addresses, meaning that it fails sooner.

Just mentioning here in case it wasn't already picked up.


Edit: it's not the latest version at the time of writing, but a branch that will solve this task: T354758: Data not retrieved by IPInfo from IPoid for IPv6 addresses - so it's not a problem yet at the time of writing, but it will become an issue soon.

Marking as resolved as I think there isn't anything else to do in this ticket. Please re-open if I am wrong.