Portus icon indicating copy to clipboard operation
Portus copied to clipboard

undefined method `name' for nil:NilClass in "app/views/public_activity/repository/_push.html.slim"

Open lokarlhorst opened this issue 11 years ago • 34 comments

If a new push event appears in Portus/Admin I get an undefined methodname' for nil:NilClass` error.

I think it happens if activity.recipient.name is nil and in db is no recipient_id

app/views/public_activity/repository/_push.html.slim related line:

= link_to "#{activity.trackable.name}:#{activity.recipient.name}", activity.trackable

A tracked activity from activities table looks like the following

| id | trackable_id | trackable_type | owner_id | owner_type | key             | parameters        | recipient_id | recipient_type | created_at          | updated_at          |
|  3 |            1 | Repository     |        4 | User       | repository.push | NULL              |         NULL | Tag            | 2015-09-15 14:17:19 | 2015-09-15 14:17:19 |

lokarlhorst avatar Sep 16 '15 11:09 lokarlhorst

In addition to that Showing /portus/app/views/repositories/show.html.slim where line #35 raised:

undefined method `username' for nil:NilClass
td= tag.author.username

lokarlhorst avatar Sep 16 '15 13:09 lokarlhorst

How can this bug be reproduced? We don't understand how the DB could have ended up in this state.

flavio avatar Sep 16 '15 14:09 flavio

We set-up our environment using LDAP and because of this, TLS for both the registry and Portus. Next, we logged in two users: the first was made an admin, the second an ordinary user. After the default namespace was created for this user, we used docker client on a remote machine to log into the registry, tag an image and push it to the registry:

docker login -u userx -e "[email protected]" registry.our.domain.com:5000
docker tag docker.io/busybox registry.our.domain.com:5000/userx/busybox
docker push registry.our.domain.com:5000/userx/busybox

This created the errors above - first the _push.html.slim error - immediately after the notification from the registry was received by Portus and either user "userx" or an admin revisited the Portus dashboard.

The second error occured after the crono-job updating Portus using the catalog was run and the UI was visited again.

morodin avatar Sep 17 '15 06:09 morodin

I cannot reproduce this issue. I've followed the exact same steps as @morodin and it works fine for me. So, some questions:

  1. Which version of Portus are you using? Is it from the appliance, master, ... ?
  2. Have you touched the DB manually or in any way in which the DB is now in an inconsistent state?
  3. Could you provide logs ?

Thanks.

mssola avatar Sep 17 '15 13:09 mssola

We used the Portus version from the master, just doing as described at the bottom from "http://suse.github.io/Portus/" (besides doing a compose-setup.sh). The code we got was from September 8th.

Before submitting the bug report, we removed all databases and redid the compose-setup. The database was empty and we did not manually change it - just did a few "select * from .. ".

Of course we can provide log. We can also add any additional debugging. What do you need?

morodin avatar Sep 17 '15 13:09 morodin

@morodin just the log/development.log file should be enough if you're using the compose setup. Moreover, just in case, could you also provide the log/crono.log file ?

Thanks!

mssola avatar Sep 17 '15 14:09 mssola

I restarted our containers, logged into the UI, logged in with the docker client and pushed another image. I uploaded the following log files to https://owncloud.fokus.fraunhofer.de/index.php/s/DGZigLkyfExFD4r

150917_registry.log - the log file from the registry. 150917_development.log - the development log file. 150917_db_output.log - the relevant part of the db 150917_crono.output - the output from the crono task.

Do you need anything else?

morodin avatar Sep 17 '15 14:09 morodin

Oh, i forgot - we changed the slim files so that the error does not occur in the moment because we have the server already under inspection by our users. Do you need us to reset the changes and run the log again with the original code?

morodin avatar Sep 17 '15 14:09 morodin

@morodin sorry to bother you, but yes, I'd appreciate if you could run the original code and pass me the logs. For what you've showed me, the DB looks inconsistent, that's I was asking previously if you had touched the DB manually. Thanks for your patience.

mssola avatar Sep 18 '15 08:09 mssola

Hey there, I've hit the same issue (I think) - I'm running the appliance, but I've replaced the docker repository with version 2.1.1. Here is the production.log file:

http://pastebin.com/Q60UKtic

One admin user, created second user, logged in, tag, push and then this happened. No code is altered from the application.

plamer avatar Sep 18 '15 16:09 plamer

I guess you are not using LDAP. Am I right?

flavio avatar Sep 18 '15 19:09 flavio

Oh, no, I'm not - sorry for missing that

plamer avatar Sep 18 '15 22:09 plamer

We commented our changes to the slim files and did the test again. You will find the logs in https://owncloud.fokus.fraunhofer.de/index.php/s/uIdSDwnqIR7LKCK

In the development log are 4 places marked with "XXX":

  • "First Error - Correcting" - after the first error, before the correction of the first slim file,
  • "Calling crono job" - before calling the crono jub,
  • "correcting second error" - after the second error, before correcting it
  • "done" - at the end of the test.

We can see the following behaviour: After the image is pushed to the registry, the "Tag page" is empty, it gets filled with the "latest" flag only after the crono job was run.

morodin avatar Sep 20 '15 18:09 morodin

@morodin sorry for the delay. Your last comment made me suspicious, I re-read the discussion again and I realized that you are using "master" from 8th September. Is that correct? If that's the case, note that there was a known regression that got fixed here. That's why you're experiencing the tags only appearing after the crono job kicks in. This leads to an unfortunate situation in which the DB gets inconsistent.

Could you update to the current master and try to reproduce this again ?

mssola avatar Sep 22 '15 09:09 mssola

@mssola: I pulled the latest from master and ran into a lot of problems - so i cant really comment on wether the issue is fixed. We are using TLS both on the registry as well the GUI. In the current master files, you use the RegistryClient, but alway with "use_ssl = false". In this case we get the following error message Could not fetch the tag for target {"mediaType"=>"application/vnd.docker.distribution.manifest.v1+json", "size"=>6709, "digest"=>"sha256:621382a9bb17b9dd62d44cb054db885de3001b99ea1eafba709915251005ad90", "length"=>6709, "repository"=>"userx/busybox8", "url"=>"https://dregistry.example.com:5000/v2/userx/busybox8/manifests/sha256:621382a9bb17b9dd62d44cb054db885de3001b99ea1eafba709915251005ad90"}.

If we change this, so that the client uses ssl (btw - shouldn't this be a configuration option?), the process gets stuck (the output is from debug messages we included in the http helper):

get_response_token: uri=dregistry.example.com,5000, use_ssl=true
calling http.request get_response_token: uri=dregistry.example.com,5000, use_ssl=true
get_response_token: uri=dregistry.example.com,3000, use_ssl=true

morodin avatar Sep 22 '15 15:09 morodin

@morodin the fact that the registry client doesn't care about SSL is a known limitation, and there should be an issue about that (I'm opening up one right now). I'll try to fix it as soon as possible and then you could try to update again and see if these issues are gone for you.

mssola avatar Sep 22 '15 16:09 mssola

Great, thanks :) Hardwiring it worked as a work-around in the last release we used - but to have it handled correctly would be fabulous.

morodin avatar Sep 22 '15 16:09 morodin

@morodin after the PR #363, it should work now. Could you update to current master and tell us if you can still reproduce this issue ? Thanks for your patience :)

mssola avatar Sep 23 '15 14:09 mssola

After a quick check it still hangs in the get_reponse_token call. I will try again tomorrow with a clean db and give you feedback.

morodin avatar Sep 23 '15 15:09 morodin

Hi guys,

I have encountered the same error as described here. I didn't use compose setup script as I am using the database on the remote machine. Portus version 1.0.1 got from the release tarball here on github. Portus and registry are both behind the reverse proxy (nginx and varnish).

Everything was set up correctly, I was able to login into UI and on a remote docker daemon but as soon as I pushed the first image to the registry it drops this error and I am not able to access the UI.

Repository Exists (0.7ms)  SELECT  1 AS one FROM `repositories` WHERE (`repositories`.`name` = BINARY 'bamboo-java-client' AND `repositories`.`id` != 1 AND `repositories`.`namespace_id` = 1) LIMIT 1
  SQL (0.7ms)  UPDATE `repositories` SET `namespace_id` = 1, `updated_at` = '2015-09-24 16:37:18' WHERE `repositories`.`id` = 1
   (27.1ms)  COMMIT
Completed 202 Accepted in 316ms (ActiveRecord: 67.5ms)


Started GET "/admin/dashboard" for 172.17.0.2 at 2015-09-24 16:37:25 +0000
Cannot render console from 172.17.0.2! Allowed networks: 127.0.0.1, ::1, 127.0.0.0/127.255.255.255
Processing by Admin::DashboardController#index as HTML
  User Load (0.9ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1  ORDER BY `users`.`id` ASC LIMIT 1
   (0.8ms)  SELECT COUNT(*) FROM `registries`
   (0.6ms)  SELECT COUNT(*) FROM `users`
   (0.6ms)  SELECT COUNT(*) FROM `teams`
   (0.6ms)  SELECT COUNT(*) FROM `namespaces`
   (0.7ms)  SELECT COUNT(count_column) FROM (SELECT  1 AS count_column FROM `activities` LIMIT 20) subquery_for_count
  PublicActivity::Activity Load (0.7ms)  SELECT  `activities`.* FROM `activities`  ORDER BY created_at DESC LIMIT 20
  User Load (0.7ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Repository Load (0.7ms)  SELECT  `repositories`.* FROM `repositories` WHERE `repositories`.`id` = 1 LIMIT 1
  Namespace Load (0.6ms)  SELECT  `namespaces`.* FROM `namespaces` WHERE `namespaces`.`id` = 1 LIMIT 1
  Registry Load (0.6ms)  SELECT  `registries`.* FROM `registries` WHERE `registries`.`id` = 1 LIMIT 1
  Rendered public_activity/repository/_push.html.slim (21.2ms)
  Rendered admin/dashboard/index.html.slim within layouts/application (115.8ms)
Completed 500 Internal Server Error in 131ms (ActiveRecord: 8.9ms)

ActionView::Template::Error (undefined method `name' for nil:NilClass):
    10:           = "#{activity.owner.username} pushed "
    11:           = link_to activity.trackable.namespace.clean_name, activity.trackable.namespace
    12:           | /
    13:           = link_to "#{activity.trackable.name}:#{activity.recipient.name}", activity.trackable
  app/views/public_activity/repository/_push.html.slim:13:in `_app_views_public_activity_repository__push_html_slim__1131702872235109430_70003304494820'
  app/views/admin/dashboard/index.html.slim:58:in `block in _app_views_admin_dashboard_index_html_slim___557323738472753169_70003267681340'
  app/views/admin/dashboard/index.html.slim:57:in `_app_views_admin_dashboard_index_html_slim___557323738472753169_70003267681340'


  Rendered /usr/local/bundle/gems/actionpack-4.2.2/lib/action_dispatch/middleware/templates/rescues/_source.erb (10.9ms)
  Rendered /usr/local/bundle/gems/actionpack-4.2.2/lib/action_dispatch/middleware/templates/rescues/_trace.html.erb (4.1ms)
  Rendered /usr/local/bundle/gems/actionpack-4.2.2/lib/action_dispatch/middleware/templates/rescues/_request_and_response.html.erb (1.1ms)
  Rendered /usr/local/bundle/gems/actionpack-4.2.2/lib/action_dispatch/middleware/templates/rescues/template_error.html.erb within rescues/layout (53.8ms)

Can you tell me which Portus version (git tag or commit-sha) this issue is addressed? If you need more details please let me know.

aleksnikolic avatar Sep 24 '15 17:09 aleksnikolic