OpenSearch icon indicating copy to clipboard operation
OpenSearch copied to clipboard

[BUG] Direct self-reference leading to cycle

Open ie-senol opened this issue 3 years ago • 9 comments

Describe the bug When a failure is met with one or more operations included in the bulk request, the ObjectMapper.writeValueAsString that we use to convert the bulk response throws the following exception:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle

and fails to convert the Bulkresponse.

With ElasticSearch, however, it works just fine and never throws this exception.

We use RestHighLevelClient for both.

To Reproduce Steps to reproduce the behavior:

  1. Run the following piece of code
ObjectMapper objectMapper = new ObjectMapper();
try {
    String jsonArray = objectMapper.writeValueAsString( bulkResponse.getItems() );
}
catch ( JsonProcessingException jsonProcessingException ) {
    log.error( jsonProcessingException.getMessage() );
    throw new RuntimeException( jsonProcessingException );
}
  1. See the following error:

com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle ( through reference chain: org.elasticsearch.action.bulk.BulkItemResponse[2]-> org.elasticsearch.action.bulk.BulkItemResponse["failure"]-> org.elasticsearch.action.bulk.BulkItemResponse$Failure["cause"]-> org.elasticsearch.ElasticsearchException["rootCause"] )

Expected behavior ObjectMapper.writeValueAsString should return JSON formatted text output of Bulkresponse without exception.

Plugins Please see the list of all plugins currently enabled. image

Host/Environment (please complete the following information):

  • MacOS 12.0.1
  • opensearch:latest

Additional context The same code doesn't throw any exception and works well with ElasticSearch.

ie-senol avatar Jan 12 '22 16:01 ie-senol

Hi @ersinoracle, Could you share the object before the serialization? the output of bulkResponse.getItems(), so we can reproduce it. In addition, could share more details about your use-case? what is the problem you are trying to solve?

anasalkouz avatar Jan 18 '22 19:01 anasalkouz

Please see the answers below.

Use-case:

  • Call bulk API using the payload which is assigned into the requestBody actual parameter
  • Convert the response to JSON so to return it to the caller

Problem:

  • ObjectMapper throws exception com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle.

Files attached (had to add .txt at the end of each file extension to be able to attach):

ie-senol avatar Jan 20 '22 01:01 ie-senol

Any updates yet?

ie-senol avatar Feb 28 '22 16:02 ie-senol

I labeled this for 1.3.0 so we don't miss it.

@ersinoracle Try turning this into a unit test if you have a moment?

dblock avatar Mar 01 '22 16:03 dblock

@dblock I, unfortunately, won't have time to write a unit test for this. But, I'll be waiting for you to address and resolve the issue hopefully in 1.3.0.

ie-senol avatar Mar 01 '22 17:03 ie-senol

Hey @ersinoracle, Sorry for being late. are you currently try to use elasticsearch client to query OpenSearch cluster.?Because the error has elasticsearch, I want to confirm this before diving into the issue. com.fasterxml.jackson.databind.exc.InvalidDefinitionException: Direct self-reference leading to cycle ( through reference chain: org.elasticsearch.action.bulk.BulkItemResponse[2]-> org.elasticsearch.action.bulk.BulkItemResponse["failure"]-> org.elasticsearch.action.bulk.BulkItemResponse$Failure["cause"]-> org.elasticsearch.ElasticsearchException["rootCause"] )

anasalkouz avatar Apr 01 '22 22:04 anasalkouz

Hi @anasalkouz, yes we still have been using it to query the OpenSearch cluster.

ie-senol avatar Apr 04 '22 15:04 ie-senol

Starting with version 7.14, multiple of the clients maintained by Elastic start to fail query OpenSearch Cluster. I would recommend update it to the equivalent OpenSearch client. See this blog for more details

anasalkouz avatar Apr 14 '22 17:04 anasalkouz

@anasalkouz this issue is tagged 2.1.0. We are code freeze for 2.1. I'll move this issue to 2.2.0, let me know if you think otherwise.

saratvemulapalli avatar Jun 28 '22 15:06 saratvemulapalli

Closing this issue. @ie-senol let me know if there is anything still pending on this to reopen.

anasalkouz avatar Sep 19 '22 20:09 anasalkouz