# Exception=\>"NoMethodError", :message=\>"undefined method \`unlock' for nil:NilClass"

**URL:** <https://discuss.elastic.co/t/exception-nomethoderror-message-undefined-method-unlock-for-nil-nilclass/165470>\
**Category:** Logstash\
**Created:** [January 23, 2019, 6:30pm UTC](https://discuss.elastic.co/t/exception-nomethoderror-message-undefined-method-unlock-for-nil-nilclass/165470 "2019-01-23T18:30:11Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![Marcos\_OS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcos_os/32/39699_2.png) [@Marcos\_OS](https://discuss.elastic.co/u/Marcos_OS)\
**Post date:** [January 23, 2019, 6:30pm UTC](https://discuss.elastic.co/t/exception-nomethoderror-message-undefined-method-unlock-for-nil-nilclass/165470/1 "2019-01-23T18:30:11Z")

</div>

Could someone help me with the following situation:

When I have the filter below, I have the expected result

```
filter {
  ruby {
	code => '
	  fieldname = event.get("type") + "datref"
	  event.set("datref", event.get(fieldname))
	'
  } 
}

```

When I add a new condition, I do not have the same result, I'm getting the error below

```
filter {
  if "jdbc" in [tags] {
    mutate {
      convert => {
        "id_sync" => "text"
      }
    }
    if ["aut", "log", "lan", "ltr"] in [tags] {
      ruby {
        code => '
          fieldname = event.get("type") + "datref"
          event.set("datref", event.get(fieldname))
        '
      }
    }
  }
}

```

ERROR\_LOG:

```
[2019-01-23T15:02:20,176][ERROR][logstash.agent] 
	Failed to execute action {:action=>LogStash::PipelineAction::Stop/pipeline_id:basa-banklink, :exception=>"NoMethodError", 
	:message=>"undefined method `unlock' for nil:NilClass", 
	:backtrace=>["/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/logstash-input-jdbc-4.3.13/lib/logstash/plugin_mixins/jdbc/jdbc.rb:213:in 
	`close_jdbc_connection'", "/usr/share/logstash/vendor/bundle/jruby/2.3.0/gems/logstash-input-jdbc-4.3.13/lib/logstash/inputs/jdbc.rb:268:in `stop'", 
	"/usr/share/logstash/logstash-core/lib/logstash/inputs/base.rb:87:in `do_stop'", "org/jruby/RubyArray.java:1734:in `each'", 
	"/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:464:in `stop_inputs'", 
	"/usr/share/logstash/logstash-core/lib/logstash/pipeline.rb:447:in `shutdown'", 
	"/usr/share/logstash/logstash-core/lib/logstash/pipeline_action/stop.rb:14:in 
	`block in execute'", "/usr/share/logstash/logstash-core/lib/logstash/pipeline_action/stop.rb:13:in `execute'",
	"/usr/share/logstash/logstash-core/lib/logstash/agent.rb:317:in `block in converge_state'"]}
```

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 23, 2019, 6:53pm UTC](https://discuss.elastic.co/t/exception-nomethoderror-message-undefined-method-unlock-for-nil-nilclass/165470/2 "2019-01-23T18:53:32Z")

</div>

I don't think it is related to the ruby filter. A jdbc input filter is shutting down, and it is trying to [unlock](https://github.com/logstash-plugins/logstash-input-jdbc/blob/288d74eba62a1f9a7bc1ffce16ff120c801a9d6b/lib/logstash/plugin_mixins/jdbc/jdbc.rb#L213) the connection. However the @connection\_lock variable in nil. Hard to see how that could be. Can you post the complete log file (or a link to it)?

---

<div class="post-metadata">

**Author:** ![Marcos\_OS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcos_os/32/39699_2.png) [@Marcos\_OS](https://discuss.elastic.co/u/Marcos_OS)\
**Post date:** [January 23, 2019, 7:22pm UTC](https://discuss.elastic.co/t/exception-nomethoderror-message-undefined-method-unlock-for-nil-nilclass/165470/3 "2019-01-23T19:22:14Z")

</div>

Thanks for the feedback.

I put the configuration files and log file at:

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 23, 2019, 8:04pm UTC](https://discuss.elastic.co/t/exception-nomethoderror-message-undefined-method-unlock-for-nil-nilclass/165470/4 "2019-01-23T20:04:59Z")

</div>

That log file does not contain that error. Please post a link to one that does.

Your configuration has 8 jdbc filters. My guess is that something is causing one of them to be closed or restarted before it has been initialialized. In fact it fails to load the pipeline because of

[ERROR][logstash.pipeline] Error registering plugin {:pipeline\_id=\>"basa-banklink", :plugin=\>"#\<LogStash::FilterDelegator:0x4c87dc67 @metric\_events\_out=org.jruby.proxy.org.logstash.instrument.metrics.counter.LongCounter$Proxy2 - name: out value:0, @metric\_events\_in=org.jruby.proxy.org.logstash.instrument.metrics.counter.LongCounter$Proxy2 - name: in value:0, @metric\_events\_time=org.jruby.proxy.org.logstash.instrument.metrics.counter.LongCounter$Proxy2 - name: duration\_in\_millis value:0, @id="896d1d111b0ae51e2f2b01f7019e66b763cacdce97dfeb0b072b90fd00d33dea", @klass=LogStash::Filters::Mutate, @metric\_events=#LogStash::Instrument::NamespacedMetric:0x6e1186f9, @filter=\<LogStash::Filters::Mutate convert=\>{"id\_sync"=\>"text"}, id=\>"896d1d111b0ae51e2f2b01f7019e66b763cacdce97dfeb0b072b90fd00d33dea", enable\_metric=\>true, periodic\_flush=\>false\>\>", :error=\>"translation missing: en.logstash.agent.configuration.invalid\_plugin\_register", :thread=\>"#\<Thread:0xe83bbea@/usr/share/logstash/logstash-core/lib/logstash/pipeline\_action/create.rb:51 run\>"}

I wonder if a pipeline restart after that would cause the problem.

---

<div class="post-metadata">

**Author:** ![Marcos\_OS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcos_os/32/39699_2.png) [@Marcos\_OS](https://discuss.elastic.co/u/Marcos_OS)\
**Post date:** [January 23, 2019, 8:18pm UTC](https://discuss.elastic.co/t/exception-nomethoderror-message-undefined-method-unlock-for-nil-nilclass/165470/5 "2019-01-23T20:18:59Z")

</div>

Sorry for the previous log.

Here is the log containing the error: `new_error_log.log` at the same address previously reported.

I reduced the configuration, I commented the pipeline.id: default

What I could not understand is that if I leave only the ruby flag code inside the filter, logstash starts and works without problem.

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 23, 2019, 8:42pm UTC](https://discuss.elastic.co/t/exception-nomethoderror-message-undefined-method-unlock-for-nil-nilclass/165470/6 "2019-01-23T20:42:07Z")

</div>

> [@Marcos\_OS](#):
>
> mutate { convert =\> { "id\_sync" =\> "text" } }

What an excellent bug! text is not valid there. You want to do a convert to 'string'. Because the mutate filter cannot initialize the rest of the pipeline configuration does not happen and it never initializes the 8 jdbc inputs. So when the config is re-read causing a pipeline restart or in the case of a shutdown you get an error referencing the unlock.

---

<div class="post-metadata">

**Author:** ![Marcos\_OS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcos_os/32/39699_2.png) [@Marcos\_OS](https://discuss.elastic.co/u/Marcos_OS)\
**Post date:** [January 23, 2019, 8:46pm UTC](https://discuss.elastic.co/t/exception-nomethoderror-message-undefined-method-unlock-for-nil-nilclass/165470/7 "2019-01-23T20:46:38Z")

</div>

Thanks for the feedback. I was writing the text below when you answered me.

```
I changed the amount of JDBC entries from 8 to 1, but I got the same error.

I believe it's something with the mutate filter, because if I remove the block exactly:

     mutate {
       convert => {
         "id_sync" => "text"
       }
     }
Logstash starts successfully.

```

So I'll rethink how I'll do this conversion out of logstash. Would you have any suggestions?

Do I need to open the bug somewhere or do you already do this just by having the post?

---

<div class="post-metadata">

**Author:** ![Badger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/badger/32/25190_2.png) [@Badger](https://discuss.elastic.co/u/Badger)\
**Post date:** [January 23, 2019, 8:48pm UTC](https://discuss.elastic.co/t/exception-nomethoderror-message-undefined-method-unlock-for-nil-nilclass/165470/8 "2019-01-23T20:48:56Z")

</div>

> [@Marcos\_OS](#):
>
> mutate { convert =\> { "id\_sync" =\> "text" } }

```
 mutate {
   convert => {
     "id_sync" => "string"
   }
 }

```

---

<div class="post-metadata">

**Author:** ![Marcos\_OS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/marcos_os/32/39699_2.png) [@Marcos\_OS](https://discuss.elastic.co/u/Marcos_OS)\
**Post date:** [January 23, 2019, 8:53pm UTC](https://discuss.elastic.co/t/exception-nomethoderror-message-undefined-method-unlock-for-nil-nilclass/165470/9 "2019-01-23T20:53:55Z")

</div>

> [@Badger](#):
>
> string

That I hesitate, I was paying attention to the types already indexed in elasticsearch and not to the types described in the address: [Mutate filter plugin | Logstash Reference [8.11] | Elastic](https://www.elastic.co/guide/en/logstash/current/plugins-filters-mutate.html)

Sorry for the unnecessary post.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 20, 2019, 8:53pm UTC](https://discuss.elastic.co/t/exception-nomethoderror-message-undefined-method-unlock-for-nil-nilclass/165470/10 "2019-02-20T20:53:59Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
