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

Missing ip & ifconfig causes mysterious errors #53

Open
brentkearney opened this issue May 21, 2022 · 3 comments · May be fixed by #55
Open

Missing ip & ifconfig causes mysterious errors #53

brentkearney opened this issue May 21, 2022 · 3 comments · May be fixed by #55

Comments

@brentkearney
Copy link

I used a new docker image to boot up an older Rails application that depends on the uuidtools gem, specifically the UUIDTools::UUID.timestamp_create method. After the image update, I was seeing a these errors in rspec tests:

      Failure/Error: uuid { UUIDTools::UUID.timestamp_create.to_s }
      
      NoMethodError:
        undefined method `[]' for nil:NilClass

This comes from the assumption that /sbin/ip will exist, at

ifconfig_path = "#{UUID.ip_path} addr list"
. It would be good if it throws a more informative error instead.

My solution was to add the OS package that included the ifconfig command (which was smaller than the one that included the ip command).

@rcalosso
Copy link

Same situation with docker image without ifconfig/ip. My errors were
5: from /srv/k2_web/vendor/bundle/ruby/2.5.0/gems/uuidtools-2.1.5/lib/uuidtools.rb:232:in timestamp_create'
4: from /srv/k2_web/vendor/bundle/ruby/2.5.0/gems/uuidtools-2.1.5/lib/uuidtools.rb:232:in synchronize' 3: from /srv/k2_web/vendor/bundle/ruby/2.5.0/gems/uuidtools-2.1.5/lib/uuidtools.rb:242:in block in timestamp_create'
2: from /srv/k2_web/vendor/bundle/ruby/2.5.0/gems/uuidtools-2.1.5/lib/uuidtools.rb:634:in mac_address' 1: from /srv/k2_web/vendor/bundle/ruby/2.5.0/gems/uuidtools-2.1.5/lib/uuidtools.rb:587:in ifconfig'
/srv/k2_web/vendor/bundle/ruby/2.5.0/gems/uuidtools-2.1.5/lib/uuidtools.rb:587:in ``': No such file or directory - addr (Errno::ENOENT)
`
If assumes ip_path is not nil:
ifconfig_path = "#{UUID.ip_path} addr list"

There is code for nil list but the error handling does not allow it.

@Richard-Degenne
Copy link

In the case neither ifconfig nor ip are available, could the gem rely on the /sys/class/net/*/address files instead?

Here is an example on Ubuntu 20.04:

$ cat /sys/class/net/*/address

02:42:5f:1b:f2:0a
02:42:7f:45:71:59
02:42:17:45:21:84
02:42:1c:c1:50:a2
02:42:58:b1:16:d5
02:42:97:94:0c:2b
02:42:c3:25:ad:02
02:42:e7:fc:98:51
02:42:6e:15:07:28
02:42:af:ad:23:70
02:42:eb:67:d5:9d
02:42:2c:cf:24:1c
02:42:c2:1a:95:fa
02:42:a5:df:68:25
02:42:ea:b1:59:39
02:42:7e:99:6f:8e
02:42:f1:4e:b5:ad
02:42:8d:71:42:39
02:42:f3:62:c3:be
74:78:27:fe:40:85
00:00:00:00:00:00
4e:f8:71:d6:dc:ed
66:87:a2:42:bf:17
1c:99:57:f2:59:0e

@Richard-Degenne
Copy link

Upon closer inspection, it seems that the gem already generates a "fake" MAC address if a real one could not be found.

nodes = SecureRandom.random_bytes(6).unpack("C*")

A quick fix to this bug could be to return nil instead of failing, and let the fallback generate a substitute instead.

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

Successfully merging a pull request may close this issue.

3 participants